-
Notifications
You must be signed in to change notification settings - Fork 176
/
hasher.py
executable file
·68 lines (57 loc) · 1.62 KB
/
hasher.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
#!/usr/bin//env python3
### github.com/bl4de | hackerone.com/bl4de ###
import sys
import hashlib
import base64
description = """
hasher.py - hash string using SHA1, MD5, Base64, Hex, Encode URL etc.
usage: ./hasher.py [string_to_hash]
"""
colors = {
"WHITE": '\33[37m',
"GREEN": '\33[32m',
"MAGENTA": '\33[35m',
"CYAN": '\33[36m',
"GREY": '\33[90m',
"LIGHTGREY": '\33[37m'
}
def usage():
'''
prints usage info
'''
print(description)
exit(0)
def hex_encode(s):
'''
HEX-encode string
'''
enc = ''
for c in s:
enc = enc + (str(hex(c)).replace('0x', ''))
return enc
def main(s):
'''
prints all hashes for provided string
'''
algorithms_available = ['md5', 'sha1', 'sha224', 'sha256', 'sha384',
'sha512', 'blake2s', 'blake2b']
print(f"\n{colors['GREEN']}HASHES:{colors['WHITE']}\n")
for h in algorithms_available:
if hasattr(hashlib, h):
try:
h_method = getattr(hashlib, h)
print(
f"{colors['GREY']}{h}\t\t{colors['CYAN']}{h_method(s.encode('utf-8')).hexdigest()}")
except TypeError as e:
pass
print(f"\n{colors['GREEN']}ENCODE:{colors['WHITE']}\n")
print(
f"{colors['GREY']}Base64 \t\t{colors['CYAN']}{base64.b64encode(s.encode('utf-8'))}")
print(
f"{colors['GREY']}HEX encoded \t{colors['CYAN']}{hex_encode(s.encode('utf-8'))}")
if __name__ == "__main__":
if (len(sys.argv) == 2):
arguments = sys.argv[1:]
main(arguments[0])
else:
usage()