- Returns an int for any object
- Use to store objects in hash tables
- Hash-tables have constant-time
O(1)lookup
Hashcode needs to be consistent with equals:
x.equals(y) => x.hashcode() == y.hashcode()A collision occurs when two objects with the same hashcode are not equal.
In Cryptography
We hash passwords with a salt to store them securely. In terms of breaking the hash, GPUs are good at this by trying different guesses in parallel.
To make things secure, we use a Sequential Memory Hard. If designed well, hash functions are not easy to brute force.
It also isn’t practical to store hashes for every possible plaintext. We use a rainbow table as a compromise between speed and space, where a reduction function maps hashes to plaintext.