I am trying to set up a Vigenère Cipher where a user both inputs a message and a keyword. The keyword shifts the of the message over by the place the letter is in the alphabet. For example, my message is 'HELLO' and my keyword is 'ABC'. The result should be 'HFNLP'. A=0 B=1 C=2 and then it starts back at A again. It works when I use capital letters but when I use lowercase it does not give me the desired result.
def generateKey(string, key):
key = list(key)
if len(string) == len(key):
return(key)
else:
for i in range(len(string) -len(key)):
key.append(key[i % len(key)])
return("" . join(key))
def encryption(string, key):
encrypt_text = []
for i in range(len(string)):
x = (ord(string[i]) +ord(key[i])) % 26
x += ord('A')
encrypt_text.append(chr(x))
return("" . join(encrypt_text))
string = input("Enter the message: ")
keyword = input("Enter the keyword: ")
key = generateKey(string, keyword)
encrypt_text = encryption(string,key)
print("Encrypted message:", encrypt_text)
When I enter 'hello' and 'ABC' it returns NLTRV. When I enter 'Hello' and 'abc' it returns NLTRV. And when I enter 'hello' and 'abc' I get TRZXB. I want all of those to be able to give me the 'HFNLP' result but I don't know why it is not. Thanks