I am coding a Caesar cipher. The key is an integer from 1 to 25. This cipher rotates the letters of the alphabet (A to Z). The encoding replaces each letter with the 1st to 25th next letter in the alphabet (wrapping Z to A). So key 2 encrypts “HI” to “JK”, but key 20 encrypts “HI” to “BC”.
But If I put in "I am super" it will output "k kc oouwrgt" when it should be "k co uwrgt" with a key of 2. It will also not go back to the beginning of the alphabet e.g 'x' will not go to 'a' with a key of 2. I use python 3.4.1
encode = []
a = "abcdefghijklmnopqrstuvwyxz"
a = list(a)
print(a)
e = input("encode or decode --->")
text = input("Sentence -->").lower()
text = list(text)
print(text)
Key = int(input("Key -->"))
if Key > 25:
print("Too high")
else:
print(Key)
if e == "encode":
for i, item in enumerate(text):
if item == " ":
encode.append(letter)
else:
num = a.index(item)
num = num + int(Key)
letter = a[num]
encode.append(letter)
for i in range(len(encode)):
print(encode[i])