-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtojson.py
50 lines (34 loc) · 1.36 KB
/
tojson.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
import binascii, hashlib, ujson
def md5(text):
return hashlib.md5(text).hexdigest().strip(), "MD5"
def sha1(text):
return hashlib.sha1(text).hexdigest().strip(), "SHA-1"
def sha256(text):
return hashlib.sha256(text).hexdigest().strip(), "SHA-256"
def sha512(text):
return hashlib.sha512(text).hexdigest().strip(), "SHA-512"
def sha384(text):
return hashlib.sha384(text).hexdigest().strip(), "SHA-384"
def sha224(text):
return hashlib.sha224(text).hexdigest().strip(), "SHA-224"
def ntlm(text):
return hashlib.new('md4', text.decode("utf-8").encode('utf-16le')).digest(), "NTLM"
filename = "500-worst-passwords.txt"
with open(filename) as f:
content = f.read().splitlines()
hashing = [md5, sha1, sha256, sha512, sha384, sha224, ntlm]
output = []
for i in content:
plaintext = bytes(i, "utf-8").strip()
for hash in hashing:
to_insert = hash(plaintext)
hashed_value = to_insert[0]
if not isinstance(hashed_value, str):
try:
hashed_value = hashed_value.decode("utf-8")
except:
continue
output.append({"Hash": to_insert[0], "Plaintext": i, "Type": to_insert[1]})
new_filename = filename.split(".")[0]
with open(new_filename + ".json", 'w') as outfile:
ujson.dump(output, outfile, reject_bytes=False)