• Welcome to Valhalla Legends Archive.
 

Key Validator

Started by BlazingKnight, October 09, 2003, 12:21 PM

Previous topic - Next topic

BlazingKnight

Can the DecodeSCKey and DecodeD2Key functions be used as a key validator?

Skywing

Quote from: BlazingKnight on October 09, 2003, 12:21 PM
Can the DecodeSCKey and DecodeD2Key functions be used as a key validator?
If you mean the YobGuls versions, they provide the same kind of protection as the game installers - protection against making a typo in the key.  Just because a key passes the installer check, though, does not mean that it will be accepted by the Battle.net server.

BlazingKnight

I'll take that as a yes. Ok, the next thing. I have a program running keys through the key decoder. There's an input list (original list), and an output list (processed through decoder). In the output list, the keys all come out different. How do I tell if it is valid or not. (True/False value).

Arta

You don't need to call decodecdkey. That'll do a whole bunch of stuff you don't need. Decoding a CD key has 3 main sections, the first is the one you're interested in - the checksum. It works by computing a value based on the characters in the key. If that character matches the last key character, the key is considered valid for an install. Otherwise, it's not. Here's my code for computing the checksum. This is reversed from battle.snp, so it won't work for Diablo II. I don't think I ever reversed that but Yobguls version should work fine if you can figure out which part it is :)


// Checksum
   DWORD Checksum = 3;
   for(int i = 0; i < 12; i++){
      Checksum += (Key[i] - 0x30) ^ (Checksum * 2);
   }

   Checksum %= 10;

   if(Key[12] != Checksum + 0x30){
      return false;
   }


The rest of the decoding gets the key's values to send to Battle.net, but since we don't know how to validate those, there's not much point in decoding them if you're only writing a validator.

BlazingKnight

Can you give that to me in VB please. Sorry for not mentioning the language.

iago

Quote from: BlazingKnight on October 09, 2003, 04:07 PM
Can you give that to me in VB please. Sorry for not mentioning the language.


// Checksum
  DWORD Checksum = 3;
  for(int i = 0; i < 12; i++){
     Checksum += (Key[i] - 0x30) ^ (Checksum * 2);
  }

  Checksum %= 10;

  if(Key[12] != Checksum + 0x30){
     return false;
  }


It shoudl be something similar to this:
dim Checksum as integer
Checksum = 3
for i = 0 to 11
Checksum = val(mid(key, i, 1)) xor (Checksum * 2)
next i

Checksum = Checksum mod 10

if Checksum != mid(key, 13, 1) then
 fail;
else
 pass;
end if


But keep in mind there's a 1/10 chance it'll pass this for a random key...
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


BlazingKnight

Thanks for converting iago. Heres what I have for my code as of now.

   Do
       Dim i As Integer
       Dim i2 As Integer
       Dim Checksum As Integer
           Checksum = 0
       Dim Key As String
           Key = lstKeys.List(i2)
       For i = 0 To 11
           Checksum = Val(Mid(Key, i, 1)) Xor (Checksum * 2)
       Next i
       Checksum = Checksum Mod 10
       If Checksum <> Mid(Key, 13, 1) Then
           lstInvalid.AddItem Key
       Else
           lstValid.AddItem Key
       End If
       i2 = i2 + 1
   Loop Until i2 = lstKeys.ListCount

I messed w/ it, but I get an "Invalid procedure call or argument" error on the line.
    Checksum = Val(Mid(Key, i, 1)) Xor (Checksum * 2)

I couldn't fix it mainly becuase I don't know what XOr and Mod mean. Please fill in the blanks for me. (Thanks)

Zakath

#7
xor is "exclusive or."

I.e. "a xor b," also expressed as "a ^ b"

a | b | a ^ b
----------------
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0

That illustrates the usage of xor. You really SHOULD know what it is, it's rather integral to programming.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

BlazingKnight

That didn't really make any sense to me. What about Mod?

iago

mod is Modulus Division, which is like the division but it returns the remainder instead of the product.

And I probably did the "mid" backwards, I haven't used it for years.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


BlazingKnight

Mid(String, Start, Stop) / Mid(strInput, 1, 4

BlazingKnight

I talked w/ Zakath in the channel. He broke it down for me some. For those who are still curious, I'll stupify it a little more for the people on my level. >.<

If you have an If/Then statement and your comparing two variables, only 1 of the variables can be true to have a true output. So...

If a = True XOr b = True then
    False Output
ElseIf a = Flse XOr b = False Then
    False Output
ElseIf a = True XOr b = False Then
    True Output
End If

Where as a regular If/Then statement would allow you to have two true variables to have a true output. Thanks Zakath.

Arta


If you have an If/Then statement and your comparing two variables, only 1 of the variables can be true to have a true output. So...


That's an OR statement. In other words, if either condition is true, the 'output' is true. If you want to change that so that both have to be true, simply use an AND statment. I've never used XOR in a conditional check and I'm not sure what the point in that would be. Is it even possible in most languages? It's more commonly used to manipulate the bits in a byte, ie:

11 XOR 5 = 14

because:

1011 (11)
0101 (5)
1110 (XOR'd - 14)

You can think of 1 as true and 0 as false if that helps.

Soul Taker

Quote from: iago on October 09, 2003, 05:04 PM
Quote from: BlazingKnight on October 09, 2003, 04:07 PM
Can you give that to me in VB please. Sorry for not mentioning the language.


// Checksum
  DWORD Checksum = 3;
  for(int i = 0; i < 12; i++){
     Checksum += (Key[i] - 0x30) ^ (Checksum * 2);
  }

  Checksum %= 10;

  if(Key[12] != Checksum + 0x30){
     return false;
  }


It shoudl be something similar to this:
dim Checksum as integer
Checksum = 3
for i = 0 to 11
Checksum = val(mid(key, i, 1)) xor (Checksum * 2)
next i

Checksum = Checksum mod 10

if Checksum != mid(key, 13, 1) then
 fail;
else
 pass;
end if


But keep in mind there's a 1/10 chance it'll pass this for a random key...
Shouldn't != be <> in VB

Arta