MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / main

Function main

ciphers/transposition_cipher_encrypt_decrypt_file.py:8–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7
8def main() -> None:
9 input_file = "./prehistoric_men.txt"
10 output_file = "./Output.txt"
11 key = int(input("Enter key: "))
12 mode = input("Encrypt/Decrypt [e/d]: ")
13
14 if not os.path.exists(input_file):
15 print(f"File {input_file} does not exist. Quitting...")
16 sys.exit()
17 if os.path.exists(output_file):
18 print(f"Overwrite {output_file}? [y/n]")
19 response = input("> ")
20 if not response.lower().startswith("y"):
21 sys.exit()
22
23 start_time = time.time()
24 if mode.lower().startswith("e"):
25 with open(input_file) as f:
26 content = f.read()
27 translated = trans_cipher.encrypt_message(key, content)
28 elif mode.lower().startswith("d"):
29 with open(output_file) as f:
30 content = f.read()
31 translated = trans_cipher.decrypt_message(key, content)
32
33 with open(output_file, "w") as output_obj:
34 output_obj.write(translated)
35
36 total_time = round(time.time() - start_time, 2)
37 print(("Done (", total_time, "seconds )"))
38
39
40if __name__ == "__main__":

Calls 1

existsMethod · 0.45

Tested by

no test coverage detected