Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
128 pmbaty 1
// Chess Giants key generator
2
 
3
#include <stdio.h>
4
#include <string.h>
5
#include <ctype.h>
6
 
7
 
8
static unsigned long ComputeRegistrationCode (const char *email);
9
 
10
 
11
int main (int argc, char **argv)
12
{
13
   // program entrypoint
14
 
15
   if (argc != 2)
16
      return (1); // incorrect usage
17
 
18
   printf ("%ld", ComputeRegistrationCode (argv[1]));
19
   return (0); // return to OS
20
}
21
 
22
 
23
static unsigned long ComputeRegistrationCode (const char *email)
24
{
25
   // quick helper to see if the program is registered. It contains an address to potential crackers.
26
   // Notice: user's email address may be a wchar_t array, and thus may contain Unicode characters.
27
   // /!\ WARNING: THE CRACKER MESSAGE SHOULD NEVER CHANGE, AND NEITHER SHOULD THE ALGORITHM BELOW /!\
28
 
29
   static const char crackermsg[] = "Please, respect my work. DON'T PUBLISH if you crack my program. Thank you and happy cracking :)";
30
 
31
   unsigned long correct_activationcode;
32
   int byte_index;
33
   int length;
34
 
35
   // compute the maximal length of the string for which we need to checksum
36
   length = strlen (email);
37
   if (length > sizeof (crackermsg) - 1)
38
      length = sizeof (crackermsg) - 1; // bound it to the length of the cracker message
39
 
40
   // hash the supplied e-mail
41
   correct_activationcode = 5381; // start value
42
   for (byte_index = 0; byte_index < sizeof (crackermsg) - 1; byte_index++)
43
      correct_activationcode = ((correct_activationcode << 5) + correct_activationcode)
44
                                 + ((unsigned long) (length > 0 ? tolower (email[byte_index % length]) : 1) // prevent zero divide
45
                                    ^ (unsigned long) crackermsg[byte_index]); // hash = hash * 33 + (char(email) ^ char(crackermsg))
46
   correct_activationcode &= 0x7FFFFFFF; // make sure the results remain positive
47
 
48
   // return the correct code
49
   return (correct_activationcode);
50
}