# expect shift <26 and shift > -26 def caesar_encode(text, shift): cipher = "" for i in range(len(text)): ord_num = ord(text[i])+shift if (ord_num > ord('z')) or (ord_num < ord('a')): ord_num -= 97 ord_num = ord_num % 26 ord_num += 97 cipher += chr(ord_num) return cipher def caesar_decode(cipher, shift): text = "" for i in range(len(cipher)): ord_num = ord(cipher[i]) - shift if ord_num < ord('a'): ord_num += 26 if ord_num > ord('z'): ord_num -= 26 text += chr(ord_num) return text print(caesar_encode("ahoj",3)) print(caesar_decode("dkrm",3))