Introduction to Hash Functions
- The primary objective of a hash function is to verify data integrity, as any alteration to even a single bit in the input message will, with high probability, produce a different hash code.
Properties of Hash Functions
A good hash function should satisfy certain properties to ensure efficient and reliable data storage, retrieval, and security.
- Deterministic: A hash function must consistently produce the same output for the same input.
- Fixed Output Size: The output of a hash function should have a fixed size, regardless of the size of the input.
- Efficiency: The hash function should be able to process input quickly.
- Uniformity: The hash function should distribute the hash values uniformly across the output space to avoid clustering.
- Pre-image Resistance: It should be computationally infeasible to reverse the hash function, i.e., to find the original input given a hash value.
- Collision Resistance: It should be difficult to find two different inputs that produce the same hash value.
- Avalanche Effect: A small change in the input should produce a significantly different hash value.
Simple Hash Functions
Phone Numbers as Input Keys
Use the last two digits of the phone number as the hash value.
Hash Function
h(k) = k mod 100
- The hash table size is 100, so valid indices range from 0 to 99
- Taking the last two digits ensures the output always falls within this range
Modular Additional Hash
Cryptographic Cash Function
- Variable Input Size: The function H can be applied to a data block or message of any arbitrary size.
- Fixed Output Size: The function H produces a fixed-length output regardless of how large or small the input message is.
- Efficiency: H(x) is relatively easy and fast to compute for any given input x, making both software and hardware implementations practical.
- Preimage Resistance (One-Way Property): For any given hash value h, it is computationally infeasible to find an input y such that H(y) = h. This property ensures that the original message or a shared secret cannot be recovered simply by observing the hash value.
- Second Preimage Resistance (Weak Collision Resistance): For any given message x, it is computationally infeasible to find a different message y ≠ × such that H(y) = H(x) This property prevents an attacker from forging an alternative message that yields the same hash code as a known message.
- Collision Resistance (Strong Collision Resistance): It is computationally infeasible to find any pair of distinct inputs (x,y) such that H(x) = H(y). This prevents attacks where an adversary prepares two different messages with identical hash values to trick a signing authority.
- Pseudorandomness: The output of H meets standard tests for pseudorandomness, producing hash values that appear evenly distributed and random.

