Skip to content

Instantly share code, notes, and snippets.

@Davnit
Created March 30, 2016 18:21
Show Gist options
  • Save Davnit/41623b0e5f98dbbb8e9888ec5631d361 to your computer and use it in GitHub Desktop.
Save Davnit/41623b0e5f98dbbb8e9888ec5631d361 to your computer and use it in GitHub Desktop.
int CDKeyDecoder::processStarCraftKey() {
int accum, pos, i;
char temp;
int hashKey = 0x13AC9741;
char cdkey[14];
std::strcpy(cdkey, this->cdkey);
// Verification
accum = 3;
for (i = 0; i < (int) (keyLen - 1); i++) {
accum += ((tolower(cdkey[i]) - '0') ^ (accum * 2));
}
if ((accum % 10) != (cdkey[12] - '0')) {
// bncsutil_debug_message_a("error: %s is not a valid StarCraft key", cdkey);
return 0;
}
// Shuffling
pos = 0x0B;
for (i = 0xC2; i >= 7; i -= 0x11) {
temp = cdkey[pos];
cdkey[pos] = cdkey[i % 0x0C];
cdkey[i % 0x0C] = temp;
pos--;
}
// Final Value
for (i = (int) (keyLen - 2); i >= 0; i--) {
temp = toupper(cdkey[i]);
cdkey[i] = temp;
if (temp <= '7') {
cdkey[i] ^= (char) (hashKey & 7);
hashKey >>= 3;
} else if (temp < 'A') {
cdkey[i] ^= ((char) i & 1);
}
}
// Final Calculations
sscanf(cdkey, "%2ld%7ld%3ld", &product, &value1, &value2);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment