Function f_encry(as_src As String, as_key As String) As String
Dim i As Integer
Dim j As Integer
Dim li_char As Integer
Dim li_mod As Integer
Dim Result As String
If Len(as_key) <= 0 Or Len(as_src) <= 0 Then
f_encry = ""
End If
If Len(as_key) < Len(as_src) Then
as_key = KiLlL_PB_Fill(as_key, Len(as_src))
End If
For i = 1 To Len(as_src)
li_char = Asc(Mid$(as_src, i, 1))
If li_char >= 33 Then
li_char = li_char - 94
End If
If li_char >= 0 Then
li_char = li_char - 94
End If
j = (i * i) * i + i * i + i + 1
li_char = li_char + 33 + KiLlL_PB_Mod(j + Asc(Mid$(as_key, i, 1)), 94)
If li_char < 0 Then
li_char = li_char + 94
End If
If li_char < 33 Then
li_char = li_char + 94
End If
Result = Result & Chr$(li_char)
Next
f_encry = Result End Function
注意这个地方跟原来的pb代码相比做了如下改动:
1.写了自己的fill函数: Public Function KiLlL_PB_Fill(a As String, b As Integer) As String
KiLlL_PB_Fill = a
Do While (Len(KiLlL_PB_Fill) < b)
KiLlL_PB_Fill = KiLlL_PB_Fill & a
Loop
KiLlL_PB_Fill = Left$(KiLlL_PB_Fill, b) End Function
2.mod函数自己写了,很简单。
3.为了方便,把数组改成了字符串。
4.在运算后再一次对ascii进行判断
If li_char < 0 Then
li_char = li_char + 94
End If
If li_char < 33 Then
li_char = li_char + 94
End If 那就顺便看看机器码是什么吧,还是这个文件:
'十六进制到十进制,支持超级大数 Public Function Hex2Dec(InputData As String) As Double
Dim i As Integer
Dim DecOut As Double
Dim Lenhex As Integer
Dim HexStep As Double
DecOut = 0
InputData = UCase$(InputData)
Lenhex = Len(InputData)
For i = 1 To Lenhex
If IsNumeric(Mid$(InputData, i, 1)) Then
GoTo NumOk
ElseIf Mid$(InputData, i, 1) = "A" Then
GoTo NumOk
ElseIf Mid$(InputData, i, 1) = "B" Then
GoTo NumOk
ElseIf Mid$(InputData, i, 1) = "C" Then
GoTo NumOk
ElseIf Mid$(InputData, i, 1) = "D" Then
GoTo NumOk
ElseIf Mid$(InputData, i, 1) = "E" Then
GoTo NumOk
ElseIf Mid$(InputData, i, 1) = "F" Then
GoTo NumOk
Else
MsgBox "Number given is not in Hex format", vbCritical
Exit Function
End If
NumOk:
Next i
HexStep = 0
For i = Lenhex To 1 Step -1
HexStep = HexStep * 16
If HexStep = 0 Then
HexStep = 1
End If
If Mid$(InputData, i, 1) = "0" Then
DecOut = DecOut + (0 * HexStep)
ElseIf Mid$(InputData, i, 1) = "1" Then
DecOut = DecOut + (1 * HexStep)
ElseIf Mid$(InputData, i, 1) = "2" Then
DecOut = DecOut + (2 * HexStep)
ElseIf Mid$(InputData, i, 1) = "3" Then
DecOut = DecOut + (3 * HexStep)
ElseIf Mid$(InputData, i, 1) = "4" Then
DecOut = DecOut + (4 * HexStep)
ElseIf Mid$(InputData, i, 1) = "5" Then
DecOut = DecOut + (5 * HexStep)
ElseIf Mid$(InputData, i, 1) = "6" Then
DecOut = DecOut + (6 * HexStep)
ElseIf Mid$(InputData, i, 1) = "7" Then
DecOut = DecOut + (7 * HexStep)
ElseIf Mid$(InputData, i, 1) = "8" Then
DecOut = DecOut + (8 * HexStep)
ElseIf Mid$(InputData, i, 1) = "9" Then
DecOut = DecOut + (9 * HexStep)
ElseIf Mid$(InputData, i, 1) = "A" Then
DecOut = DecOut + (10 * HexStep)
ElseIf Mid$(InputData, i, 1) = "B" Then
DecOut = DecOut + (11 * HexStep)
ElseIf Mid$(InputData, i, 1) = "C" Then
DecOut = DecOut + (12 * HexStep)
ElseIf Mid$(InputData, i, 1) = "D" Then
DecOut = DecOut + (13 * HexStep)
ElseIf Mid$(InputData, i, 1) = "E" Then
DecOut = DecOut + (14 * HexStep)
ElseIf Mid$(InputData, i, 1) = "F" Then
DecOut = DecOut + (15 * HexStep)
Else
MsgBox "Something is Screwed up, Wahhhhhhhhhhh", vbCritical
End If
Next i
Hex2Dec = DecOut
eds: End Function