- // Chess Giants key generator 
-   
- #include <windows.h> 
- #include <commctrl.h> 
- #include "rsrc.h" 
-   
-   
- // global variables used in this module only 
- static HINSTANCE hAppInstance; 
-   
-   
- // function prototypes 
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpCmdLine, int nCmdShow); 
- static int WINAPI MainDialogProc (HWND hWnd, unsigned int message, unsigned int wParam, long lParam); 
- static unsigned long ComputeRegistrationCode (const char *email); 
- static void CenterWindow (HWND hWnd); 
-   
-   
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpCmdLine, int nCmdShow) 
- { 
-    // program entrypoint 
-   
-    hAppInstance = hInstance; // save application instance 
-   
-    InitCommonControls (); 
-    OleInitialize (NULL); // initialize OLE (for XP style) 
-   
-    // fire up the main dialog box 
-    DialogBox (hAppInstance, (char *) DIALOG_MAIN, 0, MainDialogProc); 
-   
-    OleUninitialize (); 
-   
-    return (0); // return to Windows 
- } 
-   
-   
- static int WINAPI MainDialogProc (HWND hWnd, unsigned int message, unsigned int wParam, long lParam) 
- { 
-    // mesage handler for main dialog box 
-   
-    static char email[256]; 
-   
-    // have we just fired up this window ? 
-    if (message == WM_INITDIALOG) 
-    { 
-       // center window on screen 
-       CenterWindow (hWnd); 
-   
-       // set dialog icons (small one for title bar & big one for task manager) 
-       SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon (hAppInstance, (char *) ICON_MAIN)); 
-       SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) LoadIcon (hAppInstance, (char *) ICON_MAIN)); 
-   
-       return (1); 
-    } 
-   
-    // else did we click the close button on the title bar ? 
-    else if (message == WM_CLOSE) 
-    { 
-       EndDialog (hWnd, 0); // if so, tell the dialog box to exit 
-       return (1); 
-    } 
-   
-    // else did we alter a control INSIDE the window ? 
-    else if (message == WM_COMMAND) 
-    { 
-       // was something entered in the edit box ? 
-       if ((HIWORD (wParam) == EN_CHANGE) && (LOWORD (wParam) == EDITBOX_EMAIL)) 
-       { 
-          GetDlgItemText (hWnd, EDITBOX_EMAIL, email, sizeof (email)); 
-          if (strlen (- email ) > sizeof ("a@b.c") - 1)
 
-             SetDlgItemInt (hWnd, EDITBOX_ACTIVATIONCODE, ComputeRegistrationCode (email), 0); 
-          else 
-             SetDlgItemText (hWnd, EDITBOX_ACTIVATIONCODE, "More chars!"); 
-   
-          return (1); 
-       } 
-   
-    } 
-   
-    return (0); 
- } 
-   
-   
- 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); 
- } 
-   
-   
- static void CenterWindow (HWND hWnd) 
- { 
-    // this function centers the specified window on screen. 
-   
-    RECT rRect; 
-    int width; 
-    int height; 
-    int x; 
-    int y; 
-   
-    // get the current rectangle of the current window 
-    GetWindowRect (hWnd, &rRect); 
-    width = rRect.right - rRect.left; 
-    height = rRect.bottom - rRect.top; 
-   
-    // draw window in the center of the screen 
-    x = GetSystemMetrics (SM_CXSCREEN) / 2 - width / 2; 
-    y = GetSystemMetrics (SM_CYSCREEN) / 2 - height / 2; 
-   
-    // now ask to change the position of the window 
-    SetWindowPos (hWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); 
-   
-    return; // finished 
- } 
-