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

Hash Functions: Properties & Python Lab

The lab focuses on exploring hash functions and their properties, including determinism, avalanche effect, and collision resistance, using algorithms like MD5, SHA-1, SHA-256, and SHA-3. Participants will perform hands-on exercises with Python to hash strings, demonstrate the avalanche effect, and simulate password hashing with salt. An optional bonus task involves creating a simple blockchain to understand the implications of tampering with data.

Uploaded by

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

Hash Functions: Properties & Python Lab

The lab focuses on exploring hash functions and their properties, including determinism, avalanche effect, and collision resistance, using algorithms like MD5, SHA-1, SHA-256, and SHA-3. Participants will perform hands-on exercises with Python to hash strings, demonstrate the avalanche effect, and simulate password hashing with salt. An optional bonus task involves creating a simple blockchain to understand the implications of tampering with data.

Uploaded by

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

Lab Title: Exploring Hash Functions and Their Properties

Objective:
Understand how hash functions work, explore their key properties (determinism, avalanche
effect, collision resistance), and compare different algorithms (MD5, SHA-1, SHA-256, SHA-3).

Tools Required:
• Python 3.x
• Hashlib library (built-in)
• Optional: Online Python (e.g., [Link]
• Text editor or Jupyter Notebook

Lab Instructions:
Part 1: Basic Hashing
1. Hash a simple string using SHA-256.
• Input: "Hello"
• Use Python:
Python
import hashlib
text = "Hello"
hash_obj = hashlib.sha256([Link]())
print(hash_obj.hexdigest())

• Record the output.


2. Verify Determinism:

• Hash the same input 3 times.


• Confirm the output is identical each time.
Part 2: Avalanche Effect
1. Slightly modify the input:

• Change "Hello" to "hello" (lowercase 'h').


• Hash both and compare the outputs.
• Note how different the two hashes are.
2. Conclusion:
Write a short paragraph explaining how this demonstrates the avalanche effect.
Part 3: Collision Resistance
1. Compare MD5 and SHA-256:

• Hash two different strings:


o "abc"
o "abd"
• Use both MD5 and SHA-256.
• Observe if either algorithm produces the same hash for different inputs.
2. Research:
Look up known collision attacks on MD5 and SHA-1. Write 2–3 sentences summarizing
your findings.
Part 4: Password Hashing with Salt
1. Simulate password hashing:

• Password: "mySecurePassword123"
• Salt: "randomSalt456"
• Combine and hash using SHA-256.
• Example:
Python
password = "mySecurePassword123"
salt = "randomSalt456"
salted_input = password + salt
hash_obj = hashlib.sha256(salted_input.encode())
print("Salted Hash:", hash_obj.hexdigest())

2. Explain:
Why is salting important? What attack does it prevent?
Part 5: Blockchain Simulation (Optional Bonus)
1. Create a simple blockchain of 3 blocks:
• Each block contains:
o Index
o Data (e.g., transaction)
o Previous block’s hash
o Current block’s hash (SHA-256)
• Use Python to simulate this chain.
• Tamper with one block and show how it breaks the chain.
Deliverables:
Submit the following:

1. Python code or screenshots for each part.

2. Written answers to questions in Parts 2, 3, and 4.

3. Blockchain simulation code and explanation.

You might also like