凯撒密码原理:
plain = list(input(“请输入需要加密的明文:”))
print(plain)
key = int(input(“请输入需要移动的位数:”))
base_A = ord(‘A’)
base_a = ord(‘a’)
cipher = []
for i in plain:
if i == " “:
cipher.append(” “)
else:
if i.isupper():
base = base_A
else:
base = base_a
cipher.append(chr((ord(i) - base + key) % 26 + base))
print((ord(i) - base + key) % 26 + base)
print(”".join(cipher))
解题:编写一个生成凯撒密码的程序
最新推荐文章于 2024-09-09 00:00:00 发布