2020-05-22 06:10:11 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2020-09-28 21:41:04 +00:00
|
|
|
from . import transposition_cipher as transCipher
|
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:
|
2019-10-05 05:14:13 +00:00
|
|
|
inputFile = "Prehistoric Men.txt"
|
|
|
|
outputFile = "Output.txt"
|
|
|
|
key = int(input("Enter key: "))
|
|
|
|
mode = input("Encrypt/Decrypt [e/d]: ")
|
2018-10-19 12:48:28 +00:00
|
|
|
|
|
|
|
if not os.path.exists(inputFile):
|
2022-07-07 14:34:07 +00:00
|
|
|
print(f"File {inputFile} does not exist. Quitting...")
|
2018-10-19 12:48:28 +00:00
|
|
|
sys.exit()
|
|
|
|
if os.path.exists(outputFile):
|
2022-07-07 14:34:07 +00:00
|
|
|
print(f"Overwrite {outputFile}? [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
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
startTime = time.time()
|
2019-10-05 05:14:13 +00:00
|
|
|
if mode.lower().startswith("e"):
|
2019-01-08 08:59:23 +00:00
|
|
|
with open(inputFile) as f:
|
|
|
|
content = f.read()
|
2018-10-19 12:48:28 +00:00
|
|
|
translated = transCipher.encryptMessage(key, content)
|
2019-10-05 05:14:13 +00:00
|
|
|
elif mode.lower().startswith("d"):
|
2019-01-08 08:59:23 +00:00
|
|
|
with open(outputFile) as f:
|
|
|
|
content = f.read()
|
2019-10-05 05:14:13 +00:00
|
|
|
translated = transCipher.decryptMessage(key, content)
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
with open(outputFile, "w") as outputObj:
|
2019-01-08 08:59:23 +00:00
|
|
|
outputObj.write(translated)
|
2019-08-19 13:37:49 +00:00
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
totalTime = round(time.time() - startTime, 2)
|
2019-10-05 05:14:13 +00:00
|
|
|
print(("Done (", totalTime, "seconds )"))
|
|
|
|
|
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()
|