Skip to content

Commit 13183a0

Browse files
Farazul HodaFarazul Hoda
Farazul Hoda
authored and
Farazul Hoda
committed
message-digesting5 hashing algorithm
1 parent d73a4c2 commit 13183a0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

ciphers/md5.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Author: farazulhoda
2+
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
5+
# like checksums or simple data integrity checks.
6+
7+
8+
#By importing the hashlib library, which provides various hashing algorithms, including MD5.
9+
import hashlib
10+
11+
# Function to calculate the MD5 hash of a given input string.
12+
def calculate_md5_hash(input_string):
13+
# Create an MD5 hash object using hashlib.
14+
md5_hash = hashlib.md5()
15+
16+
# Update the hash object with the input string, encoded as bytes.
17+
md5_hash.update(input_string.encode('utf-8'))
18+
19+
# Get the hexadecimal representation of the MD5 hash.
20+
md5_hash_hex = md5_hash.hexdigest()
21+
22+
# Return the MD5 hash as a hexadecimal string.
23+
return md5_hash_hex
24+
25+
# Input string provided by the user.
26+
input_string = input("Enter a string: ")
27+
28+
# Calculate and print the MD5 hash.
29+
md5_hash = calculate_md5_hash(input_string)
30+
print(f"Input String: {input_string}")
31+
print(f"MD5 Hash: {md5_hash}")

0 commit comments

Comments
 (0)