主题:读加密函数
小弟在网上抄了一段字符串加密代码如下:
Public Function EnDeCode(ByVal strSource As String, ByVal MA As Integer) As String
On Error GoTo ErrEnDeCode '设置错误捕捉陷井
Dim CharNum As Long, RandomInteger As Integer
Dim SingleCHAR As Char
Dim strTmp As String
Dim i As Integer
Dim X As Single
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)
Do
RandomInteger = Int(127 * Rnd())
Loop While RandomInteger > 30 And RandomInteger < 100
CharNum = CharNum Xor RandomInteger
strTmp = strTmp & Chr(CharNum)
Next i
EnDeCode = strTmp
Exit Function
ErrEnDeCode:
EnDeCode = ""
MsgBox(Err.Number & Chr(13) & Err.Description)
End Function
小弟不懂的是:
1.在取随机数时,首先用X=RND(-MA)取过一次后是不是就能保证下次RND取值相同?
2.为什么随机数取值不能是30至100的数?如果是因为怕不能显示与保存,那是什么原理呢?100至127ASC码值的数都可以保存与显示呀?
请各位大虾支招,感激不尽!
Public Function EnDeCode(ByVal strSource As String, ByVal MA As Integer) As String
On Error GoTo ErrEnDeCode '设置错误捕捉陷井
Dim CharNum As Long, RandomInteger As Integer
Dim SingleCHAR As Char
Dim strTmp As String
Dim i As Integer
Dim X As Single
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)
Do
RandomInteger = Int(127 * Rnd())
Loop While RandomInteger > 30 And RandomInteger < 100
CharNum = CharNum Xor RandomInteger
strTmp = strTmp & Chr(CharNum)
Next i
EnDeCode = strTmp
Exit Function
ErrEnDeCode:
EnDeCode = ""
MsgBox(Err.Number & Chr(13) & Err.Description)
End Function
小弟不懂的是:
1.在取随机数时,首先用X=RND(-MA)取过一次后是不是就能保证下次RND取值相同?
2.为什么随机数取值不能是30至100的数?如果是因为怕不能显示与保存,那是什么原理呢?100至127ASC码值的数都可以保存与显示呀?
请各位大虾支招,感激不尽!