萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> access教程 >> access基礎教程 >> 加解密文本的函數

加解密文本的函數

Private Sub Comman1_Click()
Dim str1, str2, str3 As String
str1 = "王宇虹"
str2 = Encrypt(str1, 188, 24)
MsgBox str2
str3 = Encrypt(str2, 188, 24)
MsgBox str3
End Sub


Private Function Encrypt(ByVal strSource As String, ByVal Key1 As Byte, _
ByVal Key2 As Integer) As String
Dim bLowData As Byte
Dim bHigData As Byte
Dim i As Integer
Dim strEncrypt As String
Dim strChar As String
For i = 1 To Len(strSource)

'從待加(解)密字符串中取出一個字符

strChar = Mid(strSource, i, 1)

' 取字符的低字節和Key1進行異或運算

bLowData = AscB(MidB(strChar, 1, 1)) Xor Key1

'取字符的高字節和K2進行異或運算

bHigData = AscB(MidB(strChar, 2, 1)) Xor Key2

'將運算後的數據合成新的字符

strEncrypt = strEncrypt & ChrB(bLowData) & ChrB(bHigData)

Next
Encrypt = strEncrypt
End Function

copyright © 萬盛學電腦網 all rights reserved