Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Encode13(Product As UInt32, PublicValue As UInt32, PrivateValue As UInt32) As String
- Dim Salt As Integer = &H13AC9741
- Dim aOrd(11) As Integer = Array(6, 0, 2, 9, 3, 11, 1, 7, 5, 4, 10, 8)
- Dim Encoded As New MemoryBlock(12)
- Dim C As Byte, i As Integer, dw As UInt32
- Encoded.StringValue(0, 2) = Right("00" + Str(Product), 2)
- Encoded.StringValue(2, 7) = Right("0000000" + Str(PublicValue), 7)
- Encoded.StringValue(9, 3) = Right("000" + Str(PrivateValue), 3)
- Dim Key As String = Encoded.StringValue(0, 12)
- Encoded = New MemoryBlock(13)
- For i = 11 To 0 Step -1
- C = Asc(Mid(Key, 1 + i, 1))
- If C <= 55 Then
- Encoded.Byte(aOrd(I)) = (C Xor (Salt And 7))
- Salt = ShiftRight(Salt, 3)
- Else
- Encoded.Byte(aOrd(I)) = (C Xor I And 1)
- End If
- Next
- dw = 3
- For i = 0 To 11
- dw = dw + BitXor(Val(Chr(Encoded.Byte(i))), (dw * 2))
- Next
- dw = dw Mod 10
- Encoded.Byte(12) = Asc(Str(dw))
- Return Encoded.StringValue(0, 13)
- End Function
- Function Decode13(Key As String, ByRef ProductValue As UInt32, ByRef PublicValue As UInt32, ByRef PrivateValue As UInt32) As Boolean
- Dim Salt As Integer = &H13AC9741
- Dim aOrd(11) As Integer = Array(6, 0, 2, 9, 3, 11, 1, 7, 5, 4, 10, 8)
- Dim Decoded As New MemoryBlock(12)
- Dim C As Byte, i As Integer, dw As UInt32
- For i = 11 To 0 Step -1
- C = Asc(Mid(Key, 1 + aOrd(i), 1))
- If C <= 55 Then
- Decoded.Byte(i) = (C Xor (Salt And 7))
- Salt = ShiftRight(Salt, 3)
- Else
- Decoded.Byte(i) = (C Xor i And 1)
- End If
- Next
- dw = 3
- For i = 0 To 11
- dw = dw + BitXor(Val(Mid(Key, 1 + i, 1)), (dw * 2))
- Next
- dw = dw Mod 10
- If Val(Mid(Key, 13, 1)) = dw Then
- ProductValue = Val(Decoded.StringValue(0, 2))
- PublicValue = Val(Decoded.StringValue(2, 7))
- PrivateValue = Val(Decoded.StringValue(9, 3))
- Return True
- Else
- Return False
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement