Cryptic Reg Key

This is the post excerpt.

Okay, so as my first blog post I have chosen to add some code that I’ve been working on recently.  Somewhere on the internet I happened upon a blog somewhere (sorry I can’t remember where I read it)  This blog was talking about the way Microsoft Registration Keys worked (old Style).

In short, it stated that the XXXX-XXXX-XXXX-XXXX MS reg key works like this:  the first 4 numbers in the set must always add up to 7, so it must be something like: 2212 or 3400.

I found this interesting and wanted to see if I could duplicate the idea at least and here is the code that I came up with:

Function cypt()

Dim a1, a2 As Integer
Dim va, vb, vc, vd, ve As Integer
Do Until Val(va) + Val(vb) + Val(vc) + Val(vd) + Val(ve) = 10
va = CInt(Int((9 * Rnd()) + 1))
vb = CInt(Int((9 * Rnd()) + 1))
vc = CInt(Int((9 * Rnd()) + 1))
vd = CInt(Int((9 * Rnd()) + 1))
ve = CInt(Int((9 * Rnd()) + 1))

a1 = va & vb & vc & vd & ve
Loop

Dim v1, v2, v3, v4 As Integer
Do Until Val(v1) + Val(v2) + Val(v3) + Val(v4) = 15
v1 = CInt(Int((9 * Rnd()) + 1))
v2 = CInt(Int((9 * Rnd()) + 1))
v3 = CInt(Int((9 * Rnd()) + 1))
v4 = CInt(Int((9 * Rnd()) + 1))

a2 = v1 & v2 & v3 & v4
Loop

Return a1 & “-” & a2 & “-” & grs(5)

End Function

Function grs(ByRef length As Integer) As String
Randomize()
Dim ac As String
ac = “0123456789”

Dim i As Integer
For i = 1 To length
grs = grs & Mid$(ac, Int(Rnd() * Len(ac) + 1), 1)
Next
End Function

 

These 2 functions are the bulk of the code: Create a form with a TEXTBOX and a BUTTON. On the click-event of the button, add the following code:

textbox.clear()
textbox.text = cypt()