I want to get specific values from a for loop to add to another string to create a vigenere cipher.
here's the code.
userinput = input('enter message')
keyword = input('enter keyword')
new = ''
for a in keyword:
pass
for i in (ord(x) for x in userinput):
if 96 < i < 123: #lowercase
new += chr(97 + (i+ord(a)-97)#keeps all values in alphabet
print(new)
so the answer i want if i do 'abcd' as my message and 'ab' as my keyword the desired outcome is 'bddf' as 'a' + 'a' is 'b' and 'b' + 'b' = 'd' and etc. how would i change the code to match my desired outcome or will i have to change it completely and how would i go about doing so.
try this (you are missing the
mod 26
-part):if you like list comprehensions, you can also write
UPDATE
updated according to the wish that
a+a=b
. note thatz
is in that case the neutral element for the addition (z+char=z
).