源程序如下:
Public Function StringEnDeCodecn(strSource As String, MA) As String
'该函数只对中西文起到加密作用
'参数为:源文件,密码
On Error GoTo ErrEnDeCode
Dim X As Single
Dim CHARNUM As Long, RANDOMINTEGER As Integer
Dim SINGLECHAR As String * 1
Dim strTmp As String
If MA < 0 Then
MA = MA * (-1)
End If
X = Rnd(-MA)
For i = 1 To Len(strSource) Step 1 '取单字节内容
SINGLECHAR = Mid(strSource, i, 1)
CHARNUM = Asc(SINGLECHAR)
g: RANDOMINTEGER = Int(127 * Rnd)
If RANDOMINTEGER < 30 Or RANDOMINTEGER > 100 Then GoTo g
CHARNUM = CHARNUM Xor RANDOMINTEGER
strTmp = strTmp & Chr(CHARNUM)
Next i
StringEnDeCodecn = strTmp
Exit Function
ErrEnDeCode:
StringEnDeCodecn = ""
MsgBox Err.Number & "\" & Err.Description
End Function
使用方法:
tmp=stringEnDecn("中华人民共和国",75)
如果要解密的话,只须键入以下语句:
tmp1=stringendecn(tmp,75)
函数没问题, 你的调用方法有问题:
Private Sub Form_Load()
Dim s As String
s = UserCode("1234中文")
Debug.Print s '这里显示出来的就是一串?
Debug.Print UserDeCode(s) '这里显示出来的是加密前的原文了
End
End Sub