'加密子程序
Private Sub SubCipher(ByVal Password As String, ByVal From_Text As String, To_Text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1Dim offset As Long
Dim Str_len As Integer
Dim i As Integer
Dim ch As Integer'得到了加密的数字
offset = NumericPassword(Password)Rnd -1
'对随机数生成器做初始化的动作
Randomize offsetStr_len = Len(From_Text)
For i = 1 To Str_len
ch = Asc(Mid$(From_Text, i, 1))
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - MIN_ASC
offset = Int((NUM_ASC + 1) * Rnd)
ch = ((ch + offset) Mod NUM_ASC)
ch = ch + MIN_ASC
To_Text = To_Text & Chr$(ch)
End If
Next i
End Sub'解密子程序
Private Sub SubDecipher(ByVal Password As String, ByVal From_Text As String, To_Text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1Dim offset As Long
Dim Str_len As Integer
Dim i As Integer
Dim ch As Integeroffset = NumericPassword(Password)
Rnd -1
Randomize offsetStr_len = Len(From_Text)
For i = 1 To Str_len
ch = Asc(Mid$(From_Text, i, 1))
If ch >= MIN_ASC And ch <= MAX_ASC Then
ch = ch - MIN_ASC
offset = Int((NUM_ASC + 1) * Rnd)
ch = ((ch - offset) Mod NUM_ASC)
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
To_Text = To_Text & Chr$(ch)
End If
Next i
End Sub'将你输入的每个字符转换成密码数字
Private Function NumericPassword(ByVal Password As String) As Long
Dim Value As Long
Dim ch As Long
Dim Shift1 As Long
Dim Shift2 As Long
Dim i As Integer
Dim Str_len As Integer'得到字符串内字符的数目
Str_len = Len(Password)
'给每个字符转换成密码数字
For i = 1 To Str_len
ch = Asc(Mid$(Password, i, 1))
Value = Value Xor (ch * 2 ^ Shift1)
Value = Value Xor (ch * 2 ^ Shift2)Shift1 = (Shift1 + 7) Mod 19
Shift2 = (Shift2 + 13) Mod 23
Next i
NumericPassword = Value
End Function