]> icculus.org git repositories - taylor/freespace2.git/blob - src/cryptstring/cryptstring.cpp
fix issue with looping audio streams
[taylor/freespace2.git] / src / cryptstring / cryptstring.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Cryptstring/cryptstring.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Applet for crypting strings.
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:15  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/07 03:16:43  theoddone33
22  * The Great Newline Fix
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:08  root
25  * Initial import.
26  *
27  * 
28  * 2     10/23/98 6:21p Dave
29  *
30  * $NoKeywords: $
31  */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include "crypt.h"
37
38 int main(int argc, char **argv)
39 {
40         int i;
41         char *crypt_string;
42
43         if ( argc == 1 ) {
44                 printf("Usage: cryptstring <string1> <string2> ...\n");
45                 printf("Output will be <crypt1> <crypt2>\n");
46                 exit(1);
47         }
48
49         for ( i = 1; i < argc; i++ ) {
50                 char *s;
51
52                 s = argv[i];
53                 // if the length of the string is greater than the number of crypted symbols we
54                 // return, then pass only the maximum length
55                 if ( strlen(s) > CRYPT_STRING_LENGTH )
56                         s += (strlen(s) - CRYPT_STRING_LENGTH);
57
58                 crypt_string = jcrypt(s);
59                 printf("%s\n", crypt_string);
60         }
61
62         return 0;
63 }
64
65 char *jcrypt (char *plainstring)
66 {
67         int i,t,len;
68         static char cryptstring[CRYPT_STRING_LENGTH + 1];
69
70         len=strlen (plainstring);
71         if (len > CRYPT_STRING_LENGTH)
72                 len = CRYPT_STRING_LENGTH;
73    
74         for (i = 0;i < len; i++) {
75                 cryptstring[i]=0; 
76
77                 for (t = 0; t < len; t++) {
78                         cryptstring[i]^=(plainstring[t] ^ plainstring[i%(t+1)]);
79                         cryptstring[i]%=90;
80                         cryptstring[i]+=33;
81                 }
82         }
83
84         cryptstring[i]=0;
85         return ((char *)cryptstring);
86 }
87