大家帮帮忙..看看这个程序..
<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> <P>看了下,也看得不是很明白。</P><P>觉得NumericPassword返回的是一个用于初始化随机种子的值,它与输入的字符串有关。</P><P>而Cipher函数就根据这个值所生成的随机数来加密(同样的初始化值,使用RND时出来的随机数是一样的)。</P><P>个人意见。。。。十二点半了,睡觉。。。。</P><P>还有,Cipher不能处理中文。它只对一定范围里的字符进行处理。</P> <P>最近我在搞给中文加密的代码,头痛中.....</P><P>OK了后会发代码上来.</P>
页:
[1]