Experiment 5: MD5 and SHA
Code:
import hashlib
import timeit
def sha1_hash(data: str) -> str:
"""Returns the SHA-1 hash of the given input string."""
sha1 = hashlib.sha1()
[Link]([Link]('utf-8'))
return [Link]()
def md5_hash(data: str) -> str:
"""Returns the MD5 hash of the given input string."""
md5 = hashlib.md5()
[Link]([Link]('utf-8'))
return [Link]()
def measure_time(func, data: str, num_runs: int = 1000):
"""Measures the execution time of the given hash function."""
return [Link](lambda: func(data), number=num_runs)
# Get user input
text = input("Enter the message to hash: ")
size = len(text) # Calculate the size of the input message
# Compute hashes
sha1_result = sha1_hash(text)
md5_result = md5_hash(text)
Output: