import random digits = 5 def encrypt(text): n = len(text) key = [random.randint(0,digits) for _ in range(n)] cipher = [ord(text[i]) ^ key[i] for i in range(n)] return cipher, key def decrypt(cipher, key): text = [key[i] ^ cipher[i] for i in range(len(cipher))] return ''.join([chr(c) if good_char(chr(c)) else '' for c in text]) def good_char(c): return c.isalpha() or c == ' ' def create_hw(quotes): for i in range(len(quotes)): text = [c for c in quotes[i].lower() if good_char(c)] cipherA, keyA = encrypt(text) cipherB, keyB = encrypt(text) cipherC, keyC = encrypt(text) fout = open(f"ciphers_{i+1:02d}.txt", "w") fout.write(f'cipherA = {cipherA}\n') fout.write(f'cipherB = {cipherB}\n') fout.write(f'cipherC = {cipherC}\n') fout.close() fq = open("quotes.txt", "r") quotes = fq.readlines() create_hw(quotes)