0% found this document useful (0 votes)
30 views4 pages

ISDVExp

experiment of isd

Uploaded by

Parmar Hiren
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)
30 views4 pages

ISDVExp

experiment of isd

Uploaded by

Parmar Hiren
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
You are on page 1/ 4

3170720 INFORMATION SECURITY 210210107007

Experiment No: 11
Implementation of SHA-1
Date:
Relevant CO: Explore the concept of hashing and implement various hashing
algorithms for message integrity

Objectives: (a) to understand working fundamental of SHA-1


(b) to carry out Implementation of SHA-1.

Equipment/Instruments: Computer System, Turbo-c/ JDK


Theory:
In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function. SHA-1
produces a 160-bit hash value known as a message digest. The way this algorithm
works is that for a message of size < 264 bits it computes a 160-bit condensed output called a
message digest. The SHA-1 algorithm is designed so that it is practically infeasible to find two input
messages that hash to the same output message. A hash function such as SHA-1 is used to calculate
an alphanumeric string that serves as the cryptographic representation of a file or a piece of data.
This is called a digest and can serve as a digital signature. It is supposed to be unique and non-
reversible.

Example:

Algorithm:

STEP-1: Read the 256-bit key values.


STEP-2: Divide into five equal-sized blocks named A, B, C, D and E.
STEP-3: The blocks B, C and D are passed to the function F.
3170720 INFORMATION SECURITY 210210107007

STEP-4: The resultant value is permuted with block E.


STEP-5: The block A is shifted right by ‘s’ times and permuted with the result of step-4.

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:

1. What is the number of round computation steps in the SHA-256 algorithm?


- The number of round computation steps in the SHA-256 algorithm is 64.

2. SHA-1 produces a hash value of _____ bits ?


- SHA-1 produces a hash value of 160 bits, represented as a 40-character hexadecimal
string.

Suggested Reference:
1. https://www.geeksforgeeks.org/sha-1-hash-in-java/.

Rubric wise marks obtained:

Rubrics 1 2 3 4 5 Total
Marks
3170720 INFORMATION SECURITY 210210107007

You might also like