
提问人:网友c********1
发布时间:2022年5月2日 01:54
[简答题]
仿照例题代码编写实现凯撒密码解密程序段,上传程序代码及运行截图。
以下为加密代码,请仿照写出解密代码。
如加密过程输入 Attack at 11:20am ,输出密文:Awdfn dw 11:20dp
解密过程则是输入:Awdfn dw 11:20dp,输出明文:Attack at 11:20am
plaincode = input("请输入明文: ")
ciphertext=""
for ch in plaincode:
if "a" <= ch<= "z":
ciphertext=ciphertext+chr(97+(ord(ch)+3-97)%26)
#chr()数值转字符;ord()字符转数值 ."a"的ASCII码97,"A"asciii码是65
#依照字母序,字母的ASCII码依次加1。
#ord("A")==65 ord("a")==97
elif "A" <= ch<= "Z":
pass #请删除pass,补充语句来处理大写字母的加密问题
else:
ciphertext=ciphertext+ch
print("密文:",ciphertext)

