0% found this document useful (0 votes)
3 views2 pages

MD5 vs SHA-1 Hashing Experiment

This document provides Python code for hashing strings using SHA-1 and MD5 algorithms. It includes functions to compute the hashes and measure their execution time. The user is prompted to input a message to hash, and the results are computed for both hashing methods.

Uploaded by

Saif Madre
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

MD5 vs SHA-1 Hashing Experiment

This document provides Python code for hashing strings using SHA-1 and MD5 algorithms. It includes functions to compute the hashes and measure their execution time. The user is prompted to input a message to hash, and the results are computed for both hashing methods.

Uploaded by

Saif Madre
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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:

You might also like