名称:RC4-3加密算法
作者:Hot Rod,Doornbosch
描述:我从一个网站获得这个RC4的加密算法程序并将它做了适当的修改。当你在加密的时候,你可以指定一 个字符。但是它的速度很慢,于是我移走了程序中Xor命令,速度就变快了,但是它不能应用于数据库 中。
输入:需要加密的字符串和密码[加密(Ture),解密(False)]
输出:经过RC4-3加密的字符串
注释:Job True = Encrypt, False = Decrypt
Dim Character() As String * 1
Function RC43(inp As String, key As String, Job As Boolean) As String
Dim S() As Byte
Dim K() As Byte
Dim i As Long
Dim j As Long
Dim temp As Byte
Dim Y As Byte
Dim t As Long
Dim x As Long
Dim Outp As String
Dim r As Integer
Dim TempOutPut As Integer
Dim HoldChar As String
Dim Length As Integer
On Error GoTo ErrorHandler:
HoldChar = " $(%&注释:*+,-)./0123456789:?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz~€、¥ウЖ┆氨渤吹犯购患骄坷谅媚牌侨墒颂臀闲岩釉罩棕仝圮蒉哙徕沅彐玷殛腱眍镳耱篝貊鼬"
Length = Len(HoldChar)
ReDim Character(Length)
For x = 0 To (Length - 1)
Character(x) = Mid(HoldChar, (x + 1), 1)
Next x
ReDim S(Length)
ReDim K(Length)
For i = 0 To (Length - 1)
S(i) = i
Next
j = 1
For i = 0 To (Length - 1)
If j > Len(key) Then j = 1
K(i) = Ascii(Mid(key, j, 1))
j = j + 1
Next i
j = 0
For i = 0 To (Length - 1)
j = (j + S(i) + K(i)) Mod (Length)
temp = S(i)
S(i) = S(j)
S(j) = temp
Next i
i = 0
j = 0
For x = 1 To Len(inp)
i = (i + 1) Mod (Length)
j = (j + S(i)) Mod (Length)
temp = S(i)
S(i) = S(j)
S(j) = temp
t = (S(i) + (S(j) Mod (Length))) Mod (Length)
Y = S(t)
TempOutPut = (Ascii(Mid(inp, x, 1)))
If Job = False And (TempOutPut - Y) < 0 Then
TempOutPut = ((Length) + (TempOutPut - Y))
ElseIf Job = False Then
TempOutPut = (TempOutPut - Y)
End If
If Job = True Then
Outp = Outp & Character((TempOutPut + Y) Mod (Length))
Else
Outp = Outp & Character((TempOutPut) Mod (Length))
End If
Next
RC43 = Outp
Exit Function
ErrorHandler:
MsgBox "Error # " & vbCrLf & Error & vbCrLf & "Outp = " & Outp & vbCrLf & "Character = " & Character(hold) & vbCrLf & "Ascii = " & hold2 & vbCrLf & "Y = " & Y, , "Error"
End Function
Function Ascii(value As String) As Byte
注释:Find Value in Character Must be used instead of asc because some characters are eliminated
x = 0
While Not Character(x) = value
x = x + 1
Wend
Ascii = (x)
End Function
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073