• Welcome to Valhalla Legends Archive.
 

Generating Numbers Help

Started by MysT_DooM, December 18, 2005, 03:06 PM

Previous topic - Next topic

MysT_DooM

well past few months i've been tryin to crack the cd key algorithm.  I have found many similarties in many keys.
anywayz

I want to know how to generate a fixed number.

ex) Generate 13 digits randomly , whose 7th digit is always 0
  and digits 1-12 are less than or equal to 8

All help would be greatly appreciated.


vb6, something about that combination of numbers and letters is sexy

FrOzeN

#1
Assuming this is for StarCraft.

You should first have a look at this topic, as theres alot of discussion on it there.

As for a simple function to do this, here's something I just threw together on the spot.
Private Function GenerateCdKey() As String
    Dim CdKey As String
    Randomize
    CdKey = Replace(CStr(CLng(Rnd * 999999 + 100000)) & "0" & CStr(CLng(Rnd * 999999 + 100000)), "9", CStr(CInt(Rnd * 9)))
    GenerateCdKey = CdKey
End Function


Not exactly the best coding, but it works. Also it would be a good idea check the key generated each time with the validation code disassembled from the installer. Info on that is also in the StarCraft Keys thread, links (here and here).

[EDIT] Just noticed you said you want the digits 1-12 less than 9, before I though you ment the other 12 digits leaving the 7th 0. Anyway the code would then look like this:
Private Function GenerateCdKey() As String
    Dim CdKey As String
    Randomize
    CdKey = Replace(CStr(CLng(Rnd * 999999 + 100000)) & "0" & CStr(CLng(Rnd * 99999 + 100000)), "9", CStr(CInt(Rnd * 9))) & CStr(CInt(Rnd * 10))
    GenerateCdKey = CdKey
End Function
~ FrOzeN