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