VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - RC4-3加密算法
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:11604, 日期:2001-12-02
名称: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