/* The following is the simple algorithm used by Soldier of Fortune II to check the CD-Keys NOTE: the interesting thing of this algorithm is that the latest 2 chars of each Key are a control byte (%02x) calculated on the first 16 bytes of the key by Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org */ #define OKKO "\x00\x00\x01\x01\x00\x00\x01\x01" \ "\x01\x01\x01\x01\x01\x01\x01\x01" \ "\x01\x01\x00\x00\x01\x00\x01\x00" \ "\x00\x01\x00\x01\x01\x00\x01\x00" \ "\x01\x00\x01\x01\x00\x00\x01\x00" /* OKKO: */ /* if 0: ok */ /* if 1: wrong key */ char cdkey[], // cdkey of 18 chars (0-9, A-Z) *ptr, // pointer final; // control byte (last 2 chars of the CD-Key) */ int i; // counter unsigned long ecx, // register edx; /* control byte */ /* the latest 2 chars of each key are a control byte */ /* calculated on the first 16 bytes of the CD-Key */ sscanf(cdkey + 16, "%02X", &final); edx = 0; ptr = cdkey; for(i = 0; i < 16; i++) { if((*ptr >= 0x61) && (*ptr <= 0x7a)) *ptr += 0xe0; ecx = *ptr - 0x33; if(ecx > 0x27) break; if(OKKO[ecx]) break; edx <<= 1; edx ^= *ptr; ptr++; } edx &= 0xff; if((i == 16) && (edx == final)) fputs("\nYour Cd-Key is OK\n", stdout); else fputs("\nYour Cd-Key is invalid\n", stdout);