def Encrypt(text, key): result = "" for i in range(len(text)): char = text[i] if(char==" "): result+=" " elif (char.isupper()): result += chr((ord(char) + key-65) % 26 + 65) else: result += chr((ord(char) + key - 97) % 26 + 97) return result def Decrypt(text, key): result = "" for i in range(len(text)): char = text[i] if(char==" "): result+=" " elif (char.isupper()): result += chr((ord(char) - key-65) % 26 + 65) else: result += chr((ord(char) - key - 97) % 26 + 97) return result print(Encrypt("Hello world", 29)) print(Decrypt("Khoor zruog", 29))