-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_gen.py
More file actions
47 lines (36 loc) · 1.07 KB
/
hash_gen.py
File metadata and controls
47 lines (36 loc) · 1.07 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
import hashlib
import base64
import bcrypt
import codecs
def encode_base64(data):
return base64.b64encode(data).decode('utf-8')
def encode_hex(data):
return data.hex()
def hash_md5(data):
return hashlib.md5(data).hexdigest()
def hash_sha1(data):
return hashlib.sha1(data).hexdigest()
def hash_sha256(data):
return hashlib.sha256(data).hexdigest()
def hash_bcrypt(data):
salt = bcrypt.gensalt()
return bcrypt.hashpw(data, salt).decode('utf-8')
def apply_rot13(text):
return codecs.encode(text, 'rot_13')
def main():
text = input("Enter your string: ")
data_bytes = text.encode('utf-8')
results = {
'Base64': encode_base64(data_bytes),
'Hex': encode_hex(data_bytes),
'MD5': hash_md5(data_bytes),
'SHA-1': hash_sha1(data_bytes),
'SHA-256': hash_sha256(data_bytes),
'BCrypt': hash_bcrypt(data_bytes),
'ROT13': apply_rot13(text)
}
print("\nResults:")
for algo, res in results.items():
print(f"Algorithm: {algo:<10} | Result: {res}")
if __name__ == "__main__":
main()