0
我想在Python中創建凱撒密碼函數,但它們似乎只能用小寫字母,如何使用大寫?我試圖在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)
你想爲大寫字母發生什麼?它應該是兩個域,所以大寫字母被大寫字母和小寫字母替換爲小寫字母?還是應該將大寫字母轉換爲小寫字母?你的問題沒有被充分指定。 – JohanL