2020-05-22 06:10:11 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2022-10-12 22:54:20 +00:00
|
|
|
from . import transposition_cipher as trans_cipher
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2021-04-04 05:22:12 +00:00
|
|
|
def main() -> None:
|
2022-10-12 22:54:20 +00:00
|
|
|
input_file = "Prehistoric Men.txt"
|
|
|
|
output_file = "Output.txt"
|
2019-10-05 05:14:13 +00:00
|
|
|
key = int(input("Enter key: "))
|
|
|
|
mode = input("Encrypt/Decrypt [e/d]: ")
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2022-10-12 22:54:20 +00:00
|
|
|
if not os.path.exists(input_file):
|
|
|
|
print(f"File {input_file} does not exist. Quitting...")
|
2018-10-19 12:48:28 +00:00
|
|
|
sys.exit()
|
2022-10-12 22:54:20 +00:00
|
|
|
if os.path.exists(output_file):
|
|
|
|
print(f"Overwrite {output_file}? [y/n]")
|
2019-10-05 05:14:13 +00:00
|
|
|
response = input("> ")
|
|
|
|
if not response.lower().startswith("y"):
|
2018-10-19 12:48:28 +00:00
|
|
|
sys.exit()
|
2019-08-19 13:37:49 +00:00
|
|
|
|
2022-10-12 22:54:20 +00:00
|
|
|
start_time = time.time()
|
2019-10-05 05:14:13 +00:00
|
|
|
if mode.lower().startswith("e"):
|
2022-10-12 22:54:20 +00:00
|
|
|
with open(input_file) as f:
|
2019-01-08 08:59:23 +00:00
|
|
|
content = f.read()
|
2022-10-12 22:54:20 +00:00
|
|
|
translated = trans_cipher.encrypt_message(key, content)
|
2019-10-05 05:14:13 +00:00
|
|
|
elif mode.lower().startswith("d"):
|
2022-10-12 22:54:20 +00:00
|
|
|
with open(output_file) as f:
|
2019-01-08 08:59:23 +00:00
|
|
|
content = f.read()
|
2022-10-12 22:54:20 +00:00
|
|
|
translated = trans_cipher.decrypt_message(key, content)
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2022-10-12 22:54:20 +00:00
|
|
|
with open(output_file, "w") as output_obj:
|
|
|
|
output_obj.write(translated)
|
2019-08-19 13:37:49 +00:00
|
|
|
|
2022-10-12 22:54:20 +00:00
|
|
|
total_time = round(time.time() - start_time, 2)
|
|
|
|
print(("Done (", total_time, "seconds )"))
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2019-08-19 13:37:49 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
if __name__ == "__main__":
|
2018-10-19 12:48:28 +00:00
|
|
|
main()
|