Private Const szKeyNumber As String = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
Private Const nKeyLen As Long = 34
Private Function Digits(s As String) As Boolean
Dim b As Boolean, i As Long, c As String
b = True
For i = 1 To Len(s)
c = Mid(s, i, 1)
If InStr(szKeyNumber, c) = 0 Then
b = False
Exit For
End If
Next
Digits = b
End Function
Private Function GetKeyValue(Key As String) As Long
Dim n As Long, i As Long, p As Long
Dim d As Long
d = nKeyLen
n = 0
For i = 1 To Len(Key)
p = InStr(szKeyNumber, Mid$(Key, i, 1)) - 1
n = n * d + p
Next i
GetKeyValue = n
End Function
Private Function MirrorLong(ByVal n As Long) As Long
Dim p As Long, i As Long
p = 0
For i = 1 To 30
p = p * 2 + (n And 1)
n = n \ 2
Next i
MirrorLong = p
End Function
Public Function CheckKey(Key As String, Prefix As String, id As Long) As Long
Dim s As String, s1 As String, s2 As String, s3 As String
Dim b As Boolean, v1 As Long, v2 As Long
Dim n As Long, nn As Double
b = False
s = UCase$(Trim$(Key))
n = Len(Prefix)
If Len(s) = 15 + n And Left$(s, n + 1) = Prefix & "-" And Mid$(s, 6 + n, 1) = "-" And Mid$(s, 11 + n, 1) = "-" Then
s1 = Mid$(s, 2 + n, 4)
s2 = Mid(s, 7 + n, 4)
s3 = Mid(s, 12 + n)
If Digits(s1) And Digits(s2) And Digits(s3) Then
v1 = MirrorLong(GetKeyValue(s1 & Left$(s2, 2)))
v2 = MirrorLong(GetKeyValue(s3 & Mid$(s2, 3)))
n = nKeyLen * nKeyLen * nKeyLen
n = n * n
v1 = v1 And &H1FFFFFFF
v2 = ((Not v2) And &H1FFFFFFF) Mod n
b = (v1 = v2)
v2 = v1 \ &H100000
If b And v2 <> id Then b = False Else v1 = v1 And &HFFFFF
End If
End If
CheckKey = IIf(b, v1, -1)
End Function
应该是vb的吧
Private Const szKeyNumber As String = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
Private Const nKeyLen As Long = 34
Private Function Digits(s As String) As Boolean
Dim b As Boolean, i As Long, c As String
b = True
For i = 1 To Len(s)
c = Mid(s, i, 1)
If InStr(szKeyNumber, c) = 0 Then
b = False
Exit For
End If
Next
Digits = b
End Function
Private Function GetKeyValue(Key As String) As Long
Dim n As Long, i As Long, p As Long
Dim d As Long
d = nKeyLen
n = 0
For i = 1 To Len(Key)
p = InStr(szKeyNumber, Mid$(Key, i, 1)) - 1
n = n * d + p
Next i
GetKeyValue = n
End Function
Private Function MirrorLong(ByVal n As Long) As Long
Dim p As Long, i As Long
p = 0
For i = 1 To 30
p = p * 2 + (n And 1)
n = n \ 2
Next i
MirrorLong = p
End Function
Public Function CheckKey(Key As String, Prefix As String, id As Long) As Long
Dim s As String, s1 As String, s2 As String, s3 As String
Dim b As Boolean, v1 As Long, v2 As Long
Dim n As Long, nn As Double
b = False
s = UCase$(Trim$(Key))
n = Len(Prefix)
If Len(s) = 15 + n And Left$(s, n + 1) = Prefix & "-" And Mid$(s, 6 + n, 1) = "-" And Mid$(s, 11 + n, 1) = "-" Then
s1 = Mid$(s, 2 + n, 4)
s2 = Mid(s, 7 + n, 4)
s3 = Mid(s, 12 + n)
If Digits(s1) And Digits(s2) And Digits(s3) Then
v1 = MirrorLong(GetKeyValue(s1 & Left$(s2, 2)))
v2 = MirrorLong(GetKeyValue(s3 & Mid$(s2, 3)))
n = nKeyLen * nKeyLen * nKeyLen
n = n * n
v1 = v1 And &H1FFFFFFF
v2 = ((Not v2) And &H1FFFFFFF) Mod n
b = (v1 = v2)
v2 = v1 \ &H100000
If b And v2 <> id Then b = False Else v1 = v1 And &HFFFFF
End If
End If
CheckKey = IIf(b, v1, -1)
End Function