VB加密的问题
答案:2 悬赏:30 手机版
解决时间 2021-02-19 07:47
- 提问者网友:遮云壑
- 2021-02-18 13:29
用什么函数可以实现加密,具体点...
最佳答案
- 五星知识达人网友:醉吻情书
- 2021-02-18 14:25
用VB加密文件
文本的加密与解密
文本的加密与解密
在VB中,由于随机数生成器是伪随机数,所以根据其原理可以用于文本的
加密和解密,根据异或逻辑运算,加密和解密可以是同一个过程。
加密与解密函数代码如下。
'加密与解密函数说明:
' CharSting 加密或解密的数据
' Key 加密或解密的密钥
'函数返回值:
' 1. CharString为空时返回"1"
' 2. 加密或解密失败返回"0"
' 3. 成功则返回加密或解密后的字符串
Public Function EDcode$(CharString As String, Key As Integer)
Dim X As Single, i As Long
Dim CharNum As Integer, RandomInteger As Integer
Dim CharSingle As String * 1
On Local Error GoTo EDcodeError
EDcode$ = ""
If Len(CharString) = 0 Then
EDcode$ = "1"
Exit Function
End If
X = Rnd(-Key)
For i = 1 To Len(CharString)
CharSingle = Mid$(CharString, i, 1)
CharNum = Asc(CharSingle)
RandomInteger = Int(256 * Rnd) And &H7F
CharNum = CharNum Xor RandomInteger
CharSingle = Chr$(CharNum)
EDcode$ = EDcode$ + CharSingle
Next i
Exit Function
EDcodeError:
EDcode$ = "0"
End Function
文本的加密与解密
文本的加密与解密
在VB中,由于随机数生成器是伪随机数,所以根据其原理可以用于文本的
加密和解密,根据异或逻辑运算,加密和解密可以是同一个过程。
加密与解密函数代码如下。
'加密与解密函数说明:
' CharSting 加密或解密的数据
' Key 加密或解密的密钥
'函数返回值:
' 1. CharString为空时返回"1"
' 2. 加密或解密失败返回"0"
' 3. 成功则返回加密或解密后的字符串
Public Function EDcode$(CharString As String, Key As Integer)
Dim X As Single, i As Long
Dim CharNum As Integer, RandomInteger As Integer
Dim CharSingle As String * 1
On Local Error GoTo EDcodeError
EDcode$ = ""
If Len(CharString) = 0 Then
EDcode$ = "1"
Exit Function
End If
X = Rnd(-Key)
For i = 1 To Len(CharString)
CharSingle = Mid$(CharString, i, 1)
CharNum = Asc(CharSingle)
RandomInteger = Int(256 * Rnd) And &H7F
CharNum = CharNum Xor RandomInteger
CharSingle = Chr$(CharNum)
EDcode$ = EDcode$ + CharSingle
Next i
Exit Function
EDcodeError:
EDcode$ = "0"
End Function
全部回答
- 1楼网友:你可爱的野爹
- 2021-02-18 15:05
command1为加密,command2为解密。 原理很简单,加密时先把字符转为ascii码,再加上1个数,再转为字符。解密时则相反。 private sub command1_click() dim s1 as string dim s2 as string dim c as string dim l as integer dim i as integer s1 = text1.text l = len(s1) for i = 1 to l c = mid(s1, i, 1) if "a" <= c and c <= "z" then s2 = s2 & chr((asc(c) - asc("a") + 3) mod 26 + asc("a")) elseif "a" <= c and c <= "z" then s2 = s2 & chr((asc(c) - asc("a") + 3) mod 26 + asc("a")) else s2 = s2 & c end if next text2.text = s2 end sub private sub command2_click() dim s1 as string dim s2 as string dim c as string dim l as integer dim i as integer s1 = text3.text l = len(s1) for i = 1 to l c = mid(s1, i, 1) if "a" <= c and c <= "z" then s2 = s2 & chr((asc(c) - asc("a") - 3 + 26) mod 26 + asc("a")) elseif "a" <= c and c <= "z" then s2 = s2 & chr((asc(c) - asc("a") - 3 + 26) mod 26 + asc("a")) else s2 = s2 & c end if next text4.text = s2 end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯