一个简单的字符串加密函数
刚写的加解密函数,但密码不能为汉字Public Function str_jm(ByVal txtword As String, ByVal txtpass As String) As String
Dim B1(10), B2(10), B3(10), q1, q2, i, j As Integer
Dim txtpa As String = "" '定义待加密字符串
q1 = Len(txtpass) '密码的长度
ReDim B1(q1) '重定义数组B1为密码长度
For j = 1 To q1 'j=1到q循环
B1(j) = Asc(Mid(txtpass, j, 1)) '取ASCII码(txtPass,第j(j=1 to q)个开始,取一个字符)
Next j
q2 = Len(txtword) 'q2=textWord的长度
ReDim B2(q2) '重定义数组B1为密码长度
ReDim B3(q2) '
For j = 1 To q2 'j=1到q循环
B2(j) = Asc(Mid(txtword, j, 1)) '取ASCII码(txtWord,第j(j=1 to q)个开始,取一个字符)
Next j
j = 0
Try
'开始加密处理
For i = 1 To q2
If j < q1 Then
j = j + 1
Else
j = 1
End If
If B2(i) <> B1(j) Then
B3(i) = B2(i) Xor B1(j)
Else
B3(i) = B2(i)
End If
txtpa &= Chr(B3(i))
Next i
Catch ex As Exception
MsgBox(ex.Message + Str(B1(j)))
End Try
Return txtpa
End Function
[此贴子已经被作者于2016-9-13 17:52编辑过]