|
<P>下面是一个密码加密的程序..但我看了很久都看不懂..我想请高手帮我看一下。.想知道NumericPassword函数是干什么用的?返回的是什么?cipher函数的原理又是什么??</P>
<P>Option Explicit
Dim Cipher_text As String
Private Sub Form_Load()
Debug.Print Hex((Asc("中")))
Debug.Print Hex((Asc("国")))</P>
<P>Text1 = "": Text2 = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim Result As Integer
If KeyAscii = 13 Then
Result = MsgBox(" 密码是否正确 ?", vbYesNo + vbExclamation)
If Result = 6 Then
Cipher Text1.Text, Text1.Text, Cipher_text
Text2 = Cipher_text
Open App.Path + "\PassWord.txt" For Output As #1
Write #1, Cipher_text
Close #1
Exit Sub
Else
Text1.Text = ""
Text1.SetFocus
End If
Exit Sub
End If
End Sub
Private Sub Command1_Click()
Unload Me
End
End Sub
Private Sub Cipher(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 + 1
Dim Offset As Long
Dim Str_len As Integer, I As Integer, Ch As Integer
Offset = NumericPassword(Password)
Rnd -1
Randomize Offset
Str_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 Function NumericPassword(ByVal Password As String) As Long
Dim Value As Long, Ch As Long, Shift1 As Long, Shift2 As Long
Dim I As Integer, 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</P>
<P>
</P> |
|