一段明文如何加密为密文
答案:1 悬赏:0 手机版
解决时间 2021-11-22 05:34
- 提问者网友:半生酒醒
- 2021-11-21 07:23
一段明文如何加密为密文
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-11-21 07:40
可以用古典密码进行加密
古典密码 常用的有凯撒加密等等
要好理解的话 我说一下吧
比如 明文 abcd 密钥 5 密文 efgh 就是将字母顺序向右移动五位(位移5)
现在用 凯撒密码 加密一句话 i love you
密文为n qtaj dtz
还有一个 反字母表加密
字母表 abcdefghijklmnopqrstuvwxyz
反字母表 zyxwvutsrqponmlkjihgfedcba
比如 abcdefg 加密后为 stuvwyz
Function Caesar(str, offset)
Dim length, char, i
Caesar = ""
length = Len(str)
For i = 1 To length
char = Mid(str, i, 1)
If char >= "A" And char <= "Z" Then
char = Asc("A") + (Asc(char) - Asc("A") + offset) Mod 26
Caesar = Caesar & Chr(char)
ElseIf char >= "a" And char <= "z" Then
char = Asc("a") + (Asc(char) - Asc("a") + offset) Mod 26
Caesar = Caesar & Chr(char)
Else
Caesar = Caesar & char
End If
Next
End Function
inputbox "密文:","凯撒密码",Caesar("i love you", 5)
'"i love you" 是要加密的字符串;5是字母的位移数Input=Inputbox("输入字符加解密","反字母表加解密")
If Input="" Then Wscript.quit
For i = 1 To Len(LCase(Input))
If Mid(LCase(Input), i, 1) = "a" Then Output = Output & "z"
If Mid(LCase(Input), i, 1) = "b" Then Output = Output & "y"
If Mid(LCase(Input), i, 1) = "c" Then Output = Output & "x"
If Mid(LCase(Input), i, 1) = "d" Then Output = Output & "w"
If Mid(LCase(Input), i, 1) = "e" Then Output = Output & "v"
If Mid(LCase(Input), i, 1) = "f" Then Output = Output & "u"
If Mid(LCase(Input), i, 1) = "g" Then Output = Output & "t"
If Mid(LCase(Input), i, 1) = "h" Then Output = Output & "s"
If Mid(LCase(Input), i, 1) = "i" Then Output = Output & "r"
If Mid(LCase(Input), i, 1) = "j" Then Output = Output & "q"
If Mid(LCase(Input), i, 1) = "k" Then Output = Output & "p"
If Mid(LCase(Input), i, 1) = "l" Then Output = Output & "o"
If Mid(LCase(Input), i, 1) = "m" Then Output = Output & "n"
If Mid(LCase(Input), i, 1) = "n" Then Output = Output & "m"
If Mid(LCase(Input), i, 1) = "o" Then Output = Output & "l"
If Mid(LCase(Input), i, 1) = "p" Then Output = Output & "k"
If Mid(LCase(Input), i, 1) = "q" Then Output = Output & "j"
If Mid(LCase(Input), i, 1) = "r" Then Output = Output & "i"
If Mid(LCase(Input), i, 1) = "s" Then Output = Output & "h"
If Mid(LCase(Input), i, 1) = "t" Then Output = Output & "g"
If Mid(LCase(Input), i, 1) = "u" Then Output = Output & "f"
If Mid(LCase(Input), i, 1) = "v" Then Output = Output & "e"
If Mid(LCase(Input), i, 1) = "w" Then Output = Output & "d"
If Mid(LCase(Input), i, 1) = "x" Then Output = Output & "c"
If Mid(LCase(Input), i, 1) = "y" Then Output = Output & "b"
If Mid(LCase(Input), i, 1) = "z" Then Output = Output & "a"
If Mid(LCase(Input), i, 1) = " " Then Output = Output & " "
Next
Msgbox Output,0,"反字母表加解密"
古典密码 常用的有凯撒加密等等
要好理解的话 我说一下吧
比如 明文 abcd 密钥 5 密文 efgh 就是将字母顺序向右移动五位(位移5)
现在用 凯撒密码 加密一句话 i love you
密文为n qtaj dtz
还有一个 反字母表加密
字母表 abcdefghijklmnopqrstuvwxyz
反字母表 zyxwvutsrqponmlkjihgfedcba
比如 abcdefg 加密后为 stuvwyz
Function Caesar(str, offset)
Dim length, char, i
Caesar = ""
length = Len(str)
For i = 1 To length
char = Mid(str, i, 1)
If char >= "A" And char <= "Z" Then
char = Asc("A") + (Asc(char) - Asc("A") + offset) Mod 26
Caesar = Caesar & Chr(char)
ElseIf char >= "a" And char <= "z" Then
char = Asc("a") + (Asc(char) - Asc("a") + offset) Mod 26
Caesar = Caesar & Chr(char)
Else
Caesar = Caesar & char
End If
Next
End Function
inputbox "密文:","凯撒密码",Caesar("i love you", 5)
'"i love you" 是要加密的字符串;5是字母的位移数Input=Inputbox("输入字符加解密","反字母表加解密")
If Input="" Then Wscript.quit
For i = 1 To Len(LCase(Input))
If Mid(LCase(Input), i, 1) = "a" Then Output = Output & "z"
If Mid(LCase(Input), i, 1) = "b" Then Output = Output & "y"
If Mid(LCase(Input), i, 1) = "c" Then Output = Output & "x"
If Mid(LCase(Input), i, 1) = "d" Then Output = Output & "w"
If Mid(LCase(Input), i, 1) = "e" Then Output = Output & "v"
If Mid(LCase(Input), i, 1) = "f" Then Output = Output & "u"
If Mid(LCase(Input), i, 1) = "g" Then Output = Output & "t"
If Mid(LCase(Input), i, 1) = "h" Then Output = Output & "s"
If Mid(LCase(Input), i, 1) = "i" Then Output = Output & "r"
If Mid(LCase(Input), i, 1) = "j" Then Output = Output & "q"
If Mid(LCase(Input), i, 1) = "k" Then Output = Output & "p"
If Mid(LCase(Input), i, 1) = "l" Then Output = Output & "o"
If Mid(LCase(Input), i, 1) = "m" Then Output = Output & "n"
If Mid(LCase(Input), i, 1) = "n" Then Output = Output & "m"
If Mid(LCase(Input), i, 1) = "o" Then Output = Output & "l"
If Mid(LCase(Input), i, 1) = "p" Then Output = Output & "k"
If Mid(LCase(Input), i, 1) = "q" Then Output = Output & "j"
If Mid(LCase(Input), i, 1) = "r" Then Output = Output & "i"
If Mid(LCase(Input), i, 1) = "s" Then Output = Output & "h"
If Mid(LCase(Input), i, 1) = "t" Then Output = Output & "g"
If Mid(LCase(Input), i, 1) = "u" Then Output = Output & "f"
If Mid(LCase(Input), i, 1) = "v" Then Output = Output & "e"
If Mid(LCase(Input), i, 1) = "w" Then Output = Output & "d"
If Mid(LCase(Input), i, 1) = "x" Then Output = Output & "c"
If Mid(LCase(Input), i, 1) = "y" Then Output = Output & "b"
If Mid(LCase(Input), i, 1) = "z" Then Output = Output & "a"
If Mid(LCase(Input), i, 1) = " " Then Output = Output & " "
Next
Msgbox Output,0,"反字母表加解密"
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯