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.
Assuming this is for StarCraft.
You should first have a look at this topic (http://forum.valhallalegends.com/index.php?topic=13318.0), 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 (http://forum.valhallalegends.com/index.php?topic=13318.msg135640#msg135640) and here (http://forum.valhallalegends.com/index.php?topic=13318.msg136588#msg136588)).
[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