【发布时间】:2018-01-15 06:11:43
【问题描述】:
我正在尝试在 Python 中创建凯撒密码函数,但它们似乎只适用于小写字母,如何使用大写字母?
a = dict(zip("abcdefghijklmnopqrstuvwxyz",range(26)))
b = dict(zip(range(26),"abcdefghijklmnopqrstuvwxyz"))
key = int(input('Enter the key:'))
plaintext = (input('Enter your message:'))
ciphertext = ""
for c in plaintext:
if c.isalpha():
ciphertext += b[ (a[c] + key)%26 ]
else: ciphertext += c
plaintext2 = ""
for c in ciphertext:
if c.isalpha():
plaintext2 += b[ (a[c] - key)%26 ]
else: plaintext2 += c
print(plaintext,",",ciphertext,",",plaintext2)
【问题讨论】:
-
您希望大写字母发生什么?是不是应该是两个域,大写换大写,小写换小写?还是应该将大写字母转换为小写字母?您的问题没有得到充分说明。
标签: python math caesar-cipher letter