I'm having issues getting my output to shift the amount asked in my program. It works when my decoded word is one letter and my keyword is only one letter. Any solutions to fix the output so that it can shift multiple letters rather than just one?
def functions(decoded_list, keyword_list, ):
shift_keyword_list = []
position_decoded_list = []
for letters in keyword_list:
if letters in alpha:
shift_keyword_list.append(alpha.index(letters))
for letters in decoded_list:
if letters in alpha:
position_decoded_list.append(alpha.index(letters))
return(shift_keyword_list, position_decoded_list)
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
decoded = input("Enter an english phrase in lowercase: ")
decoded_list = list(decoded.upper())
keyword = input("Enter your key: ")
keyword_list = list(keyword.upper())
# v1 = keyword_list // v2 = decoded_list
v1, v2 = functions(decoded_list, keyword_list)
# changes the lists into integers
# int_v1 = decoded_list // int_v2 = keyword_list
int_v1 = (v1)
string_v1 = [str(int_v1) for int_v1 in int_v1]
str_v1 = ''.join(string_v1)
int_v1 = int(str_v1)
int_v2 = v2
string_v2 = [str(int_v2) for int_v2 in int_v2]
str_v2 = ''.join(string_v2)
int_v2 = int(str_v2)
encoded = ''
for letters in range(int_v1):
encoded += alpha[(int_v2 + int_v1) % 26]
print(encoded.upper())
break
Since the purpose of this is to encode text, you want your final loop to loop through the input text, not just a simple range. Something like this:
However, what you're doing is not a Vigenere cipher, which is much simpler than what you've done. Here is a Vigenere cipher: