- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy pathtransposition_cipher_encrypt_decrypt_file.py
41 lines (32 loc) · 1.14 KB
/
transposition_cipher_encrypt_decrypt_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
importos
importsys
importtime
from . importtransposition_cipherastrans_cipher
defmain() ->None:
input_file="./prehistoric_men.txt"
output_file="./Output.txt"
key=int(input("Enter key: "))
mode=input("Encrypt/Decrypt [e/d]: ")
ifnotos.path.exists(input_file):
print(f"File {input_file} does not exist. Quitting...")
sys.exit()
ifos.path.exists(output_file):
print(f"Overwrite {output_file}? [y/n]")
response=input("> ")
ifnotresponse.lower().startswith("y"):
sys.exit()
start_time=time.time()
ifmode.lower().startswith("e"):
withopen(input_file) asf:
content=f.read()
translated=trans_cipher.encrypt_message(key, content)
elifmode.lower().startswith("d"):
withopen(output_file) asf:
content=f.read()
translated=trans_cipher.decrypt_message(key, content)
withopen(output_file, "w") asoutput_obj:
output_obj.write(translated)
total_time=round(time.time() -start_time, 2)
print(("Done (", total_time, "seconds )"))
if__name__=="__main__":
main()