I want to encrypt some letters by changing each letter with the character in echaracters
which has the same index as the letter in characters
.
So, I tried to use zip()
to iterate over the two lists.
Firstly I iterated over userInput
and the within the same loop, I iterated over key
(which is zip(characters, echaracters)
)
Then I check if i
is equal to a
and if the condition is True
i add b
to cipher
.
userInput = input("Enter: ")
characters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
echaracters = ["@", "$", "(", "]", "=", ")", "&", "#", "!", "%", "~", "[", "/", ";", "*", "}", "9", "?", "5", "1", "_", ">", "<<", "+", ",", "-"]
key = zip(characters, echaracters)
cipher = ""
for i in userInput:
for a, b in key:
if i == a:
cipher += b
print(cipher)
OUTPUT
Enter: ABC
@
I cannot figure out why it returns only the first symbol.
DESIRED OUTPUT
Enter: ABC
@$(
What am I doing wrong?