forked from rwils83/CTF_cryptochallenge_decoder-decryptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·89 lines (70 loc) · 2.6 KB
/
app.py
File metadata and controls
executable file
·89 lines (70 loc) · 2.6 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import base64 as b
import argparse
import codecs
def base64_Encode(test=None):
if test == None:
cleartext = raw_input("Enter the string to encode \n")
else:
cleartext = test
return b.b64encode(cleartext)
def base64_Decode(test=None):
if test == None:
encoded_text = raw_input("Enter the string to decode \n")
else:
encoded_text = test
try:
return b.b64decode(encoded_text)
except:
return "Please enter a base64 encoded string"
def base32_Encode(test=None):
if test == None:
cleartext = raw_input("Enter the string to encode \n")
else:
cleartext = test
return b.b32encode(cleartext)
def base32_Decode(test=None):
if test == None:
encodedtext = raw_input("Enter the string to decode \n")
else:
encodedtext = test
try:
return b.b32decode(encodedtext)
except:
return "Please enter a base32 encoded string"
def rot_13_encrypt(test=None):
if test == None:
cleartext = raw_input("Enter the string to encrypt \n")
else:
cleartext = test
return codecs.encode(cleartext, "rot_13")
def rot_13_decrypt(test=None):
if test == None:
cleartext = raw_input("Enter the string to decrypt \n")
else:
cleartext = test
return codecs.decode(cleartext, "rot_13")
def parse_args():
description = "Encode, Decode, Encrypt, Decrypt basic CTF challenges"
parser = argparse.ArgumentParser(description=description)
parser.add_argument("-d", "--decrypt", action="store_true", help = "Decode/Decrypt")
parser.add_argument("-e", "--encrypt", action="store_true", help = "Encode/Encrypt")
parser.add_argument("-b64", "--base64", action="store_true", help="Use for base64 with -d or -e")
parser.add_argument("-b32", "--base32", action="store_true", help="Use for base32 with -d or -e")
parser.add_argument("-r13", "--rot13", action="store_true", help="Use for Rot13 with -d or -e")
parser.add_argument("-s", "--string", action="store", help="String to encrypt/decrypt")
args = parser.parse_args()
return args
if __name__ == "__main__":
args = parse_args()
if args.base64 and args.decrypt:
print base64_Decode(args.string)
if args.base64 and args.encrypt:
print base64_Encode(args.string)
if args.base32 and args.decrypt:
print base32_Decode(args.string)
if args.base32 and args.encrypt:
print base32_Encode(args.string)
if args.rot13 and args.decrypt:
print rot_13_decrypt(args.string)
if args.rot13 and args.encrypt:
print rot_13_encrypt(args.string)