]> icculus.org git repositories - taylor/freespace2.git/blob - src/cryptstring/cryptstring.cpp
The Great Newline Fix
[taylor/freespace2.git] / src / cryptstring / cryptstring.cpp
1 /*
2  * $Logfile: /Freespace2/code/Cryptstring/cryptstring.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Applet for crypting strings.
8  *
9  * $Log$
10  * Revision 1.2  2002/05/07 03:16:43  theoddone33
11  * The Great Newline Fix
12  *
13  * Revision 1.1.1.1  2002/05/03 03:28:08  root
14  * Initial import.
15  *
16  * 
17  * 2     10/23/98 6:21p Dave
18  *
19  * $NoKeywords: $
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "crypt.h"
26
27 int main(int argc, char **argv)
28 {
29         int i;
30         char *crypt_string;
31
32         if ( argc == 1 ) {
33                 printf("Usage: cryptstring <string1> <string2> ...\n");
34                 printf("Output will be <crypt1> <crypt2>\n");
35                 exit(1);
36         }
37
38         for ( i = 1; i < argc; i++ ) {
39                 char *s;
40
41                 s = argv[i];
42                 // if the length of the string is greater than the number of crypted symbols we
43                 // return, then pass only the maximum length
44                 if ( strlen(s) > CRYPT_STRING_LENGTH )
45                         s += (strlen(s) - CRYPT_STRING_LENGTH);
46
47                 crypt_string = jcrypt(s);
48                 printf("%s\n", crypt_string);
49         }
50
51         return 0;
52 }
53
54 char *jcrypt (char *plainstring)
55 {
56         int i,t,len;
57         static char cryptstring[CRYPT_STRING_LENGTH + 1];
58
59         len=strlen (plainstring);
60         if (len > CRYPT_STRING_LENGTH)
61                 len = CRYPT_STRING_LENGTH;
62    
63         for (i = 0;i < len; i++) {
64                 cryptstring[i]=0; 
65
66                 for (t = 0; t < len; t++) {
67                         cryptstring[i]^=(plainstring[t] ^ plainstring[i%(t+1)]);
68                         cryptstring[i]%=90;
69                         cryptstring[i]+=33;
70                 }
71         }
72
73         cryptstring[i]=0;
74         return ((char *)cryptstring);
75 }
76