/* The following is the simple algorithm used by Half-Life to know if a CD-Key is valid or not. by Luigi Auriemma e-mail: aluigi@autistici.org web: aluigi.org */ unsigned char cdkey[], /* buffer that contains the Half-life CD-KEY */ /* the key must be 13 bytes long and all the */ /* '-' chars must be removed */ *ptr; // a pointer for faster operations unsigned long eax, edx, edi, i; // counter eax = 3; ptr = cdkey; for(i = 0; i < 12; i++, ptr++) { edi = eax << 1; edx = *ptr - 0x30; // char '0' edx ^= edi; eax += edx; } eax %= 10; eax -= *ptr; if(eax == 0xFFFFFFD0) fputs("CD-Key is OK!\n", stdout); else fputs("CD-Key is invalid\n", stdout);