-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoder.py
71 lines (56 loc) · 1.83 KB
/
decoder.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
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
#!/usr/bin/env python3
import sys
import getopt
import argparse
from base64 import *
import morse_talk as mtalk
import binascii
import pprint
from base58 import *
# PARSER
parser = argparse.ArgumentParser(prog="decoder.py", usage=None, description="Autodecode encrypted messages using all supported methods", epilog=None, parents=[
], formatter_class=argparse.HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)
# ARGUMENTS
file_string = parser.add_mutually_exclusive_group(required=False)
file_string.add_argument("-s", "--string", help="Encrypted string")
file_string.add_argument(
"-f", "--file", help="File that contain the encrypted string")
parser.add_argument("-a", "--all", action='store_false',
help="Bruteforce all methods",)
parsed = parser.parse_args(sys.argv[1:])
def bruteforce(string):
results = {}
# BASES
base = {16: b16decode, 32: b32decode, 58:b58decode, 64: b64decode, 85: b85decode}
for i in base.keys():
try:
results['b'+str(i)] = base[i](string)
except:
pass
# print("error base: "+str(i))
# MORSE
try:
results['morse'] = mtalk.decode(string)
except Exception as e:
pass
# HEX
try:
results['hex'] = bytearray.fromhex(string).decode()
except Exception as e:
pass
# BINARY, OCTAL, DECIMAL
for base in [2,8,10]:
try:
results['base-'+str(base)] = "".join([chr(int(i,base=base)) for i in string.split()])
except Exception as e:
pass
print()
pprint.pprint(results)
print()
def main(args):
if len(sys.argv[1:]) < 1:
parser.print_help()
elif not args.all:
bruteforce(args.string)
if __name__ == "__main__":
main(parsed)