-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_random_hash.py
More file actions
79 lines (68 loc) · 2.34 KB
/
gen_random_hash.py
File metadata and controls
79 lines (68 loc) · 2.34 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
import uuid
import hashlib
"""
This is just a reminder about hashing...
Here is what hashlib provides:
hashlib: algorithms_available
hashlib: algorithms_guaranteed
hashlib: blake2b
hashlib: blake2s
See: https://medium.com/@kdaminingclub/unraveling-the-blake2s-hash-algorithm-a-comprehensive-guide-8eb00c95c52c
"Compared to other algorithms like SHA-256 and SHA-3, Blake2S is just as secure but much faster. This makes it a popular choice for many people and companies (Aumasson et al., 2013)."
hashlib: file_digest
hashlib: md5
hashlib: new
hashlib: pbkdf2_hmac
hashlib: sha1
hashlib: sha224
hashlib: sha256
hashlib: sha384
hashlib: sha3_224
hashlib: sha3_256
hashlib: sha3_384
hashlib: sha3_512
hashlib: sha512
hashlib: shake_128
hashlib: shake_256
"""
ones = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
tens = "1 10 20 30 40 50 60 70 8"
separator = '- - - - - - - - - - - - - - - - - - - - -'
def generate_random_hash() -> tuple[str, str]:
random_uuid = str(uuid.uuid4()).encode('utf-8')
# print(f"random uuid = {random_uuid}")
# Use the algorithm most appropriate to your use case.
# hash_object = hashlib.sha512()
# hash_algo = "sha512"
# hash_object = hashlib.sha256()
# hash_algo = "sha256"
# hash_object = hashlib.sha1()
# hash_algo = "sha1"
# hash_object = hashlib.blake2b()
# hash_algo = "blake2b"
# I'm using blake for safety, speed,
# simplicity and possibly quantum readiness.
hash_object = hashlib.blake2s()
hash_algo = "blake2s"
# hash_object = hashlib.shake_128()
# hash_algo = "shake_128"
hash_object.update(random_uuid)
return hash_object.hexdigest(), hash_algo
def explore_hashlib():
print(f"{separator}")
eh = ''
for eh in sorted(hashlib.__all__):
print('hashlib: ', end='')
print(eh, end='\n')
print(f"{separator}\r\n")
def explore_hashlib_algos():
print(f"{separator}\r\n")
print(f"hashlib.algorithms_available: {hashlib.algorithms_available}")
print(f"{separator}\r\n")
print(f"hashlib.algorithms_guaranteed: {hashlib.algorithms_guaranteed}")
print(f"{separator}\r\n")
random_hash, hash_algo = generate_random_hash()
print(f"Random Hash using {hash_algo}:")
print(f"{random_hash}")
# print(f"{ones}")
# print(f"{tens}")