I have this function that decodes a letter by a given key
def decode_char(n, key):
adj = ord('a') if n.islower() else ord('A')
return chr(adj + (ord(n)-adj-int(key))%26)
I am trying to get this to work, so a word is decoded
def decode_block(word,key):
letters = list(word)
keys = list(key)
decoded = []
for letter, digit in zip(letters, keys):
decoded.append(decode_char(letter, digit))
return "".join(decoded)
when I input this
print(decode_char('bddffhhj', '12121212'))
I get this error message
TypeError: ord() expected a character, but string of length 8 found
I need to get
abcdefgh
I can't figure out why the ord(n)
in decode_char
isn't recieveing a character?
I have split the word into a list? and zipped these to the digits of the key?
Just a student so please don't go ham
Anyone?