I am writing a program on shifting a word. My desired output should be a:f b:g c:h ... y:d z:e A:F B:G C:H ... Y:D Z:E
import string
letters = string.ascii_letters #contains 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
#create the Caesar cypher
offset = 5 #choose your shift
totalLetters = 26
keys = {} #use dictionary for letter mapping
invkeys = {} #use dictionary for inverse letter mapping, you could use inverse search from original dict
for index, letter in enumerate(letters):
# cypher setup
if index < totalLetters: #lowercase
letter = letters[index]
keys[letter] = letters[(index offset) % 26]
print(letters[index] ":" keys[letter])
else: #uppercase
letter = letters.isupper()
keys[letter] = letters[(index offset) % 26]
print(letters[index] ":" keys[letter])
But after running this code, my output is a:f b:g c:h ... y:d z:e A:f B:g C:h ... Y:d Z:e
Seems isupper()
function didn't work here. Could you help with this based on my code structure. Thanks in advance!
CodePudding user response:
in uppercase
condition,
keys[letter] = letters[(index offset) % 26 26]