Currently doing a Vigenere cipher in Python, and me and many people in my class are stuck on one aspect.
After we translated the keyword to ordinals, we need to add those number to a message to encrypt it. This is my code so far.
Input = input('Enter your message: ')
key = input('Enter the one word key: ')
times = len(Input)//len(key)+1
encryptedKey = (times*key)[:len(Input)]
output = []
for character in Input:
number = ord(character) - 96
output.append(number)
outputKey = []
for character in encryptedKey:
numberKey = ord(character) - 96
outputKey.append(numberKey)
print(encryptedKey)
print(outputKey)
print(Input)
print(output)
So if the Input is 'hello'
, and the key is 'bye'
, the keyword would become 'byeby'
[2,25,5,2,25]
, and 'hello'
would be [8,5,12,12,15]
. I can't figure out a way to add the first 2
with 8
, the 25
with 5
, and so on.
I tried print(sum(output + outputKey))
but of course that just adds all the numbers together, meaning the answer is 111
.
I also need them to turn back into letters, so that it ends up with the encrypted message.
Thanks!