VB文本加密类的详细介绍

VB文本加密类的详细介绍

'加密与解密函数说明:
'CharSting加密或解密的数据
'Key加密或解密的密钥
'函数返回值:
'1. CharString为空时返回"1"
'2. 加密或解密失败返回"0"
'3. 成功则返回加密或解密后的字符串
Public Function EDcode$(CharString As String, Key As Integer)
Dim X As Single, i As Long
Dim CharNum As Integer, RandomInteger As Integer
Dim CharSingle As String * 1
On Local Error GoTo EDcodeError
EDcode$ = ""
If Len(CharString) = 0 Then
EDcode$ = "1"
Exit Function
End If
X = Rnd(-Key)
For i = 1 To Len(CharString)
CharSingle = Mid$(CharString, i, 1)
CharNum = Asc(CharSingle)
RandomInteger = Int(256 * Rnd) And &H7F
CharNum = CharNum Xor RandomInteger
CharSingle = Chr$(CharNum)
EDcode$ = EDcode$ + CharSingle
Next i
Exit Function
EDcodeError:
EDcode$ = "0"
End Function