From 6d3720b0f9e7adee8acbf16e5a4b3eeb4e64c163 Mon Sep 17 00:00:00 2001 From: Kristian Krsnik Date: Fri, 25 Aug 2023 00:20:15 +0200 Subject: [PATCH] 156 --- README.md | 8 +++++ exercises/166/inputs/flag.txt.en | 1 + exercises/166/inputs/pw.txt | 1 + exercises/166/main.py | 60 ++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 exercises/166/inputs/flag.txt.en create mode 100644 exercises/166/inputs/pw.txt create mode 100644 exercises/166/main.py diff --git a/README.md b/README.md index f20b1ac..68fef83 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,11 @@ The folder name is the challenge id, as found in the URL ( 4: + print(usage_msg) + sys.exit(1) + + + +if sys.argv[1] == "-e": + if len(sys.argv) < 4: + sim_sala_bim = input("Please enter the password:") + else: + sim_sala_bim = sys.argv[3] + + ssb_b64 = base64.b64encode(sim_sala_bim.encode()) + c = Fernet(ssb_b64) + + with open(sys.argv[2], "rb") as f: + data = f.read() + data_c = c.encrypt(data) + sys.stdout.write(data_c.decode()) + + +elif sys.argv[1] == "-d": + if len(sys.argv) < 4: + sim_sala_bim = input("Please enter the password:") + else: + sim_sala_bim = sys.argv[3] + + ssb_b64 = base64.b64encode(sim_sala_bim.encode()) + c = Fernet(ssb_b64) + + with open(sys.argv[2], "r") as f: + data = f.read() + data_c = c.decrypt(data.encode()) + sys.stdout.buffer.write(data_c) + + +elif sys.argv[1] == "-h" or sys.argv[1] == "--help": + print(help_msg) + sys.exit(1) + + +else: + print("Unrecognized first argument: "+ sys.argv[1]) + print("Please use '-e', '-d', or '-h'.") +