// Chess Giants key generator
#include <stdio.h>
#include <string.h>
#include <ctype.h>
static unsigned long ComputeRegistrationCode (const char *email);
int main (int argc, char **argv)
{
// program entrypoint
if (argc != 2)
return (1); // incorrect usage
printf ("%ld", ComputeRegistrationCode
(argv
[1]));
return (0); // return to OS
}
static unsigned long ComputeRegistrationCode (const char *email)
{
// quick helper to see if the program is registered. It contains an address to potential crackers.
// Notice: user's email address may be a wchar_t array, and thus may contain Unicode characters.
// /!\ WARNING: THE CRACKER MESSAGE SHOULD NEVER CHANGE, AND NEITHER SHOULD THE ALGORITHM BELOW /!\
static const char crackermsg[] = "Please, respect my work. DON'T PUBLISH if you crack my program. Thank you and happy cracking :)";
unsigned long correct_activationcode;
int byte_index;
int length;
// compute the maximal length of the string for which we need to checksum
if (length > sizeof (crackermsg) - 1)
length = sizeof (crackermsg) - 1; // bound it to the length of the cracker message
// hash the supplied e-mail
correct_activationcode = 5381; // start value
for (byte_index = 0; byte_index < sizeof (crackermsg) - 1; byte_index++)
correct_activationcode = ((correct_activationcode << 5) + correct_activationcode)
+ ((unsigned long) (length
> 0 ? tolower (email
[byte_index
% length
]) : 1) // prevent zero divide
^ (unsigned long) crackermsg[byte_index]); // hash = hash * 33 + (char(email) ^ char(crackermsg))
correct_activationcode &= 0x7FFFFFFF; // make sure the results remain positive
// return the correct code
return (correct_activationcode);
}