I'm using a list of the alphabet, the user enters a keyword and the keyword gets indexed and added to the text you want to be encrypted. it does this however, if it is more than one character e.g. 'ab' it will only recognize it as the last character; '2' instead of '3'. Please help, thanks in advance
key = [123, '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']
def encrypt(k, plaintext):
result = ''
for l in k:
try:
p = (key.index(l)) %26
print p
except ValueError:
result += 1
for l in plaintext:
try:
i = (key.index(l) + p) %26
result += key[i]
print i
except ValueError:
result += l
return result.upper()