|
- Public Function StringEnDeCodecn(ByVal strSource As String, ByVal enCode As Single) As String
- '该函数只对中西文起到加密作用
- '参数strSource为:需要加密的字符,参数enCode为:密钥
- '加密:?StringEnDeCodecn("Access爱好者","123456")
- ' JR.O\板簣征
- '解密:?StringEnDeCodecn("JR.O\板簣征","123456")
- ' Access爱好者
- On Error GoTo ErrEnDeCode
- Dim X As Single
- Dim strNum As Long, rndInt As Integer
- Dim sChar As String * 1
- Dim strTmp As String
- Dim i As Integer
- If enCode = 0 Then enCode = 1
- If enCode < 0 Then
- enCode = enCode * (-1)
- End If
- X = Rnd(-enCode)
- For i = 1 To Len(strSource) Step 1
- sChar = Mid(strSource, i, 1)
- strNum = Asc(sChar)
- g:
- rndInt = Int(127 * Rnd)
- If rndInt < 30 Or rndInt > 100 Then GoTo g
- strNum = strNum Xor rndInt
- strTmp = strTmp & Chr(strNum)
- Next i
- StringEnDeCodecn = strTmp
- Exit Function
- ErrEnDeCode:
- StringEnDeCodecn = ""
- MsgBox Err.Number & "" & Err.Description
- End Function
复制代码 |
|