-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhasher.py
42 lines (35 loc) · 1.6 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
import hashlib
# This module, hashlib, implements a common interface to many different secure hash
# including SHA1, SHA224, SHA256, SHA384, and SHA512, as well as MD5 algorithm
# --------------------------------------------------
# MD5:
hashvalue = input("* Enter a string to hash:")
hash_handle_1 = hashlib.md5()
hash_handle_1.update(hashvalue.encode())
print("The MD5 hash value is: ", hash_handle_1.hexdigest())
# --------------------------------------------------
# sha-1:
hash_handle_2 = hashlib.sha1()
# string.encode(): It returns an utf-8 encoded version of the string
# update: Update the hash object with the bytes-like object.
# Byte objects are in machine readable form internally, Strings are only in human readable form.
hash_handle_2.update(hashvalue.encode())
# return the digest as a string object of double length, containing only hexadecimal digits.
# the hash value is a hexadecimal string.
print("The sha-1 hash value is: ", hash_handle_2.hexdigest())
# --------------------------------------------------
# sha-224:
hash_handle_3 = hashlib.sha224()
hash_handle_3.update(hashvalue.encode())
print("The sha-224 hash value is: ", hash_handle_3.hexdigest())
# --------------------------------------------------
# sha-256:
hash_handle_4 = hashlib.sha256()
hash_handle_4.update(hashvalue.encode())
print("The sha-256 hash value is: ", hash_handle_4.hexdigest())
# --------------------------------------------------
# sha-512:
hash_handle_5 = hashlib.sha512()
hash_handle_5.update(hashvalue.encode())
print("The sha-512 hash value is: ", hash_handle_5.hexdigest())
# --------------------------------------------------