9555 CSS Lab3
9555 CSS Lab3
9555 CSS Lab3
Practical No: 5
Date of Performance:
Date of Submission:
Evaluation:
Sr. No Rubric Grade
1 On time submission
Or completion (2)
2 Preparedness(2)
3 Skill (4)
4 Output (2)
Signature of the Teacher:
Date:
Lab Objective:
Theory:
Cryptographic hash functions are a very useful tool in cryptography. They are applied in many
areas like integrity of messages, storage of passwords securely and protect signatures. The three
hash algorithms SHA-1, SHA-512 and MD5 are considered to analyze their performance.
MD5
∙ Takes as input a message of arbitrary length and produces as output a 128 bit
“fingerprint” or “message digest” of the input.
∙ It is conjectured that it is computationally infeasible to produce two messages having the
same message digest.
∙ Intended where a large file must be “compressed” in a secure manner before being
encrypted with a private key under a public-key cryptosystem such as PGP
Input:
Suppose a b-bit message as input, and that we need to find its message digest.
Algorithm:
Step 1 – append padding bits:
– The message is padded so that its length is congruent to 448, modulo
512. - Means extended to just 64 bits of being of 512 bits long.
– A single “1” bit is appended to the message, and then “0” bits are appended so that
the length in bits equals 448 modulo 512.
In addition MD5 uses four auxiliary functions that each take as input three 32-bit words and
produce as output one 32-bit word. They apply the logical operators and, or, not and xor to the
input bits.
MD5 further uses a table K that has 64 elements. Element number i is indicated as Ki. The
table is computed beforehand to speed up the computations. The elements are computed using
the mathematical sin function:
The figure shows how the auxiliary function F is applied to the four buffers (A, B, C and D),
using message word Mi and constant Ki. The item "<<<s" denotes a binary left shift by s bits.
Round 1.
[abcd k s i] denote the operation a = b + ((a + F (b, c, d) + X [k] + T [i]) <<< s).
Output:
SHA-1
Processing is similar to SHA-1 with small variations. In SHA-1, chaining variables are 5 and
Boolean operations are different.
Lab Manual prepared by : Prof. Monali Shetty
Analysis
1 KB 1.3828277587890625e-05 1.6450881958007812e-05
5 KB 2.4080276489257812e-05 2.2172927856445312e-05
10 KB 3.0040740966796875e-05 2.2411346435546875e-05
file_path = "1kbfile.txt"
begin=time.time()
md5_hash = calculate_md5(file_path)
end=time.time()
print("MD5 hash:", md5_hash)
print("Total time taken is ",end-begin)
SHA1:
import hashlib
import time
def calculate_sha1(file_path):
with open(file_path, "rb") as f:
# Read the file in binary mode
content = f.read()
# Calculate SHA1 hash
md5_hash = hashlib.sha1(content).hexdigest()
return md5_hash
file_path = "1kbfile.txt"
begin=time.time()
sha1_hash = calculate_sha1(file_path)
end=time.time()
print("SHA1 hash:", sha1_hash)
print("Total time taken is ",end-begin)