-
Notifications
You must be signed in to change notification settings - Fork 0
/
cyber_tools.py
65 lines (53 loc) · 1.66 KB
/
cyber_tools.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
import hashlib
def show_algorithms_available():
print(hashlib.algorithms_guaranteed)
def hashes_match(h1, h2):
if (h1 == h2):
return True
else:
return False
def get_popular_passwords_from_file(file_name, p_list):
with open(file_name) as file:
for line in file:
line = line.rstrip("\n")
p_list.append(line)
def get_hashed_password(plaintext_password, algo="sha1"):
pw = plaintext_password.encode()
shake = False
if algo == "sha1":
hash_object = hashlib.sha1(pw)
elif algo == "sha256":
hash_object = hashlib.sha256(pw)
elif algo == "sha512":
hash_object = hashlib.sha512(pw)
elif algo == "sha224":
hash_object = hashlib.sha224(pw)
elif algo == "sha384":
hash_object = hashlib.sha384(pw)
elif algo == "sha3_256":
hash_object = hashlib.sha3_256(pw)
elif algo == "sha3_512":
hash_object = hashlib.sha3_512(pw)
elif algo == "sha3_224":
hash_object = hashlib.sha3_224(pw)
elif algo == "sha3_384":
hash_object = hashlib.sha3_384(pw)
elif algo == "md5":
hash_object = hashlib.md5(pw)
elif algo == "blake2b":
hash_object = hashlib.blake2b(pw)
elif algo == "blake2s":
hash_object = hashlib.blake2s(pw)
elif algo.startswith('shake'):
shake = True
if algo == 'shake_128':
hash_object = hashlib.shake_128()
if algo == 'shake_256':
hash_object = hashlib.shake_128()
else:
hash_object = None
if shake:
hex_dig = hash_object.hexdigest(16)
else:
hex_dig = hash_object.hexdigest()
return hex_dig