Posted By

simoncoder on 06/14/17

Who likes this?

1 person have marked this snippet as a favorite

Microsoft Type Registration Key

/ Published in: VB.NET

This function will create a REG Key XXXXX-XXXX-XXXXX where the first 5 numbers always add up to 10, the second set always adds up to 15 and the final set is always random.

`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     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click        'Add a BUTTON and a TEXTBOX        tx1.Clear() 'Clears the textbox        tx1.Text = cypt()     End Sub`