1
1
# Author: farazulhoda
2
2
3
3
# A Python program that calculates the MD5 (Message Digest 5) hash of a given string using the hashlib library.
4
- # While MD5 is considered weak and not suitable for cryptographic purposes, it can still be used for non-security-related purposes
4
+ # While MD5 is considered weak and not suitable for cryptographic purposes, it can still be used for non-security-related purposes
5
5
# like checksums or simple data integrity checks.
6
6
7
7
8
- #By importing the hashlib library, which provides various hashing algorithms, including MD5.
8
+ # By importing the hashlib library, which provides various hashing algorithms, including MD5.
9
9
import hashlib
10
10
11
+
11
12
# Function to calculate the MD5 hash of a given input string.
12
13
def calculate_md5_hash (input_string ):
13
14
# Create an MD5 hash object using hashlib.
14
15
md5_hash = hashlib .md5 ()
15
16
16
17
# Update the hash object with the input string, encoded as bytes.
17
- md5_hash .update (input_string .encode (' utf-8' ))
18
+ md5_hash .update (input_string .encode (" utf-8" ))
18
19
19
20
# Get the hexadecimal representation of the MD5 hash.
20
21
md5_hash_hex = md5_hash .hexdigest ()
21
22
22
23
# Return the MD5 hash as a hexadecimal string.
23
24
return md5_hash_hex
24
25
26
+
25
27
# Input string provided by the user.
26
28
input_string = input ("Enter a string: " )
27
29
28
30
# Calculate and print the MD5 hash.
29
31
md5_hash = calculate_md5_hash (input_string )
30
32
print (f"Input String: { input_string } " )
31
- print (f"MD5 Hash: { md5_hash } " )
33
+ print (f"MD5 Hash: { md5_hash } " )
0 commit comments