ISDVExp
ISDVExp
Experiment No: 11
Implementation of SHA-1
Date:
Relevant CO: Explore the concept of hashing and implement various hashing
algorithms for message integrity
Example:
Algorithm:
STEP-6: Then it is permuted with a weight value and then with some other key pair and
taken as the first block.
STEP-7: Block A is taken as the second block and the block B is shifted by ‘s’ times and
taken as the third block.
STEP-8: The blocks C and D are taken as the block D and E for the final output.
Program:
import hashlib
def md5_hash(data):
"""
Compute the MD5 hash value of the input data.
Args:
data (str): The input data to be hashed.
Returns:
str: The MD5 hash value as a 32-character hexadecimal string.
"""
md5 = hashlib.md5()
md5.update(data.encode('utf-8'))
return md5.hexdigest()
def sha256_hash(data):
"""
Compute the SHA-256 hash value of the input data.
Args:
data (str): The input data to be hashed.
Returns:
str: The SHA-256 hash value as a 64-character hexadecimal string.
"""
sha256 = hashlib.sha256()
sha256.update(data.encode('utf-8'))
return sha256.hexdigest()
def sha512_hash(data):
"""
Compute the SHA-512 hash value of the input data.
3170720 INFORMATION SECURITY 210210107007
Args:
data (str): The input data to be hashed.
Returns:
str: The SHA-512 hash value as a 128-character hexadecimal string.
"""
sha512 = hashlib.sha512()
sha512.update(data.encode('utf-8'))
return sha512.hexdigest()
# Example usage:
data = "Hello, World!"
print("MD5 Hash:", md5_hash(data))
print("SHA-256 Hash:", sha256_hash(data))
print("SHA-512 Hash:", sha512_hash(data))
Output:
MD5 Hash: 65a8e27d8879283831b664bd8b7f0ad4
SHA-256 Hash: 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3
SHA-512 Hash:
9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c1
1d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
Conclusion:
- In this response, we explored the concept of hashing and implemented various hashing
algorithms for message integrity using Python. We discussed the properties of hashing
algorithms and implemented MD5, SHA-256, and SHA-512 hashing algorithms. The
implementation demonstrates the working fundamentals of hashing and provides a
practical example of how to compute the hash value of a given message.
Quiz:
Suggested Reference:
1. https://www.geeksforgeeks.org/sha-1-hash-in-java/.
Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210210107007