with open("plain_text.txt") as f: plain = f.readline() def caesar_encrypt(text, shift = 3): encrypted_text = "" for char in text: if char.isalpha(): ascii_offset = ord('A') if char.isupper() else ord('a') encrypted_char = chr((ord(char) - ascii_offset + shift) % 26 + ascii_offset) encrypted_text += encrypted_char else: encrypted_text += char return encrypted_text cipher = caesar_encrypt(plain) with open("cipher_text.txt","w") as f: f.write(cipher)