diff options
author | William Carroll <wpcarro@gmail.com> | 2021-12-29T16·09-0400 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2021-12-29T19·34+0000 |
commit | 5c0ec720afc83761d1afda44e9b6acd30375d898 (patch) | |
tree | 45b8d18a0f53420038415855e1aa8684712b142d /users/wpcarro/scratch/picoctf/challenge_166/ende.py | |
parent | d3c20a44d37f0246dc9d848e6c63da2839f8dc4f (diff) |
feat(wpcarro/scratch): Upload my solutions to picoCTF challenges r/3500
Just getting my feet wet... Change-Id: Ia1db0c69fe7d5ea5cb5585853d0688ef97f2680a Reviewed-on: https://cl.tvl.fyi/c/depot/+/4739 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/scratch/picoctf/challenge_166/ende.py')
-rw-r--r-- | users/wpcarro/scratch/picoctf/challenge_166/ende.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/picoctf/challenge_166/ende.py b/users/wpcarro/scratch/picoctf/challenge_166/ende.py new file mode 100644 index 000000000000..08395f920909 --- /dev/null +++ b/users/wpcarro/scratch/picoctf/challenge_166/ende.py @@ -0,0 +1,60 @@ + +import sys +import base64 +from cryptography.fernet import Fernet + + + +usage_msg = "Usage: "+ sys.argv[0] +" (-e/-d) [file]" +help_msg = usage_msg + "\n" +\ + "Examples:\n" +\ + " To decrypt a file named 'pole.txt', do: " +\ + "'$ python "+ sys.argv[0] +" -d pole.txt'\n" + + + +if len(sys.argv) < 2 or len(sys.argv) > 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'.") + |