一款简单实用的加密算法:RC4,其源代码如下:
'RC4加密算法
'RC4是对称加密算法,其中:
' Expr
' Password 是密钥
'返回:明文或密文
Public Function RC4(ByVal Expr
On Error Resume Next
Dim RB(0 To 255) As Integer,X As Long,Y As Long,Z As Long,Key() As Byte,ByteArray() As Byte,Temp As Byte
If Len(Password) = 0 Then
Exit Function
End If
If Len(Expr
Exit Function
End If
If Len(Password) > 256 Then
Key() = StrConv(Left$(Password,256),vbFromUnicode)
Else
Key() = StrConv(Password,vbFromUnicode)
End If
For X = 0 To 255
RB(X) = X
Next X
X = 0
Y = 0
Z = 0
For X = 0 To 255
Y = (Y + RB(X) + Key(X Mod Len(Password))) Mod 256
Temp = RB(X)
RB(X) = RB(Y)
RB(Y) = Temp
Next X
X = 0
Y = 0
Z = 0
ByteArray() = StrConv(Expr
For X = 0 To Len(Expr
Y = (Y + 1) Mod 256
Z = (Z + RB(Y)) Mod 256
Temp = RB(Y)
RB(Y) = RB(Z)
RB(Z) = Temp
ByteArray(X) = ByteArray(X) Xor (RB((RB(Y) + RB(Z)) Mod 256))
Next X
RC4 = StrConv(ByteArray,vbUnicode)
End Function
平常保密性不是很高的情况下,用它,我觉得也差不多了。
RSA/DES的源代码暂时未找到,此代码来源于http://freevbcode.com
在问专家找到的DES/3DES的加、解密源代码。