()
| 113 | |
| 114 | |
| 115 | def main() -> None: |
| 116 | filename = "encrypted_file.txt" |
| 117 | response = input(r"Encrypt\Decrypt [e\d]: ") |
| 118 | |
| 119 | if response.lower().startswith("e"): |
| 120 | mode = "encrypt" |
| 121 | elif response.lower().startswith("d"): |
| 122 | mode = "decrypt" |
| 123 | |
| 124 | if mode == "encrypt": |
| 125 | if not os.path.exists("rsa_pubkey.txt"): |
| 126 | rkg.make_key_files("rsa", 1024) |
| 127 | |
| 128 | message = input("\nEnter message: ") |
| 129 | pubkey_filename = "rsa_pubkey.txt" |
| 130 | print(f"Encrypting and writing to {filename}...") |
| 131 | encrypted_text = encrypt_and_write_to_file(filename, pubkey_filename, message) |
| 132 | |
| 133 | print("\nEncrypted text:") |
| 134 | print(encrypted_text) |
| 135 | |
| 136 | elif mode == "decrypt": |
| 137 | privkey_filename = "rsa_privkey.txt" |
| 138 | print(f"Reading from {filename} and decrypting...") |
| 139 | decrypted_text = read_from_file_and_decrypt(filename, privkey_filename) |
| 140 | print("writing decryption to rsa_decryption.txt...") |
| 141 | with open("rsa_decryption.txt", "w") as dec: |
| 142 | dec.write(decrypted_text) |
| 143 | |
| 144 | print("\nDecryption:") |
| 145 | print(decrypted_text) |
| 146 | |
| 147 | |
| 148 | if __name__ == "__main__": |
no test coverage detected