• Welcome to Valhalla Legends Archive.
 

Starcraft Cdkey Decode

Started by Yegg, February 28, 2006, 04:41 PM

Previous topic - Next topic

Yegg

I'm having a lot of trouble getting a smaller version of the Starcraft cdkey decode function based off of the Python version that netytan and I wrote. The code is a almost a direct conversion from Python to C, yet C returns different results. Here is the code for the C version,

void DecodeStarcraftKey(char *key) {
short i = 11;
int c, v = 0x13AC9741, seq[] = {6, 0, 2, 9, 3, 11, 1, 7, 5, 4, 10, 8};
for (; i > 0; i--) {
c = key[seq[i]];
if (c < 55) {
c = v & 0xFF & 7 ^ c;
v >>= 3;
} else c = i & 1 ^ c;
key[i] = c;
}
}


If I were to decode "1234567890123" with this function, my final result would be: "1404591935083". However, the Python version would be: "7263531935083". Below I will show the comparisons of the variable, c in the Python version, and the C version. For the most part they are the same, a few values change and this ruins the rest of the function.

Python:
9
1
5
6
8
2
2
4
0
3
1
7

C:
9
1
5
6
8
2
8
4
5
3
1

netytan and I have already wasted enough time on this and really have gotten nowhere with it. The Python version outputs 12 values if you include a print c in there, including a printf() (for c variable) in C outputs only 11 variables. This is obviously wrong. This code is becoming quite annoying, so for the time being I've given up on it. If I figure anything out I'll be sure to update my post. Any help would be greatly appreciated.

l2k-Shadow

#1

short i = 11;
for (; i > 0; i--)


Well now this is why it only outputs 11 numbers. You are telling it ok i = 11 and decrement i by 1 while i is bigger than 0.

for (; i >= 0; i--)

^ works better.

Also

if (c < 55)

is incorrect. Should be:

if (c <= 55)


also try

c ^= ((v & 0xff) & 7)

better coding habit..

plenty of fixed can be done on that code. the else should be an else if, although i dont think it matters:

else if (c < 65) {
c ^= (i & 1)
}




Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Yegg

Thank you shadow, I also received help from hdx. He noted that I could not just replace the characters in key[] the way I was doing. I need to create a second char array and output the chars taken from key[] to my new char array (deckey[]). Here's the new code:

void DecodeStarcraftKey(char *key, char *deckey) {
short i = 11;
int c, v = 0x13AC9741, seq[] = {6, 0, 2, 9, 3, 11, 1, 7, 5, 4, 10, 8};
deckey[12] = key[12];
for (; i >= 0; i--) {
c = key[seq[i]];
if (c <= 55) {
c ^= (v & 0xff & 7);
v >>= 3;
} else c ^= i & 1;
deckey[i] = c;
}
}