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.