Q:

Ascii decoding function in Python, what's wrong?

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?

A:

The problem is with decode_char. It should be almost the same as code_char, except for subtracting the key integer instead of adding it. Here's a repaired version.
def decode_char(n, key):
    adj = ord('a') if n.islower() else ord('A') 
    return chr(adj + (ord(n)-adj-int(key))%26)

I don't understand why you have encrypt and code_block. You can get rid of encrypt and rename code_block to encrypt. The same goes for decrypt / decode_block.

