Professional Documents
Culture Documents
Sec: 7A
Merkle Damgard Construction
Information Security
Roll: 20p-0019
1. **Padding**: If the message length is not a multiple of the block size, padding
is applied to make it fit.
2. **Divide into Blocks**: The padded message is divided into equal-sized blocks.
6. **Finalization**: The final value of the chaining variable is the hash output.
Source Code:
import hashlib
# Simulated compression function (a simple XOR operation)
def custom_compression(chaining_var, block):
# Perform a bitwise XOR between chaining_var and block
return chaining_var ^ block
# Initialization
chaining_var = 0
# Finalization
return chaining_var
# Example usage
message = b"Hello, World!"
block_size = 4 # In bytes
hash_output = merkle_damgard(message, block_size, custom_compression)
print(f"Hash output: {hash_output:x}")
```