Trusted answers to developer questions

Anjana Shankar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In simple words, a **hash function** is a function that maps any arbitrary value to a certain fixed range.

For example, you may want to map the values from 1 to 100 within a range of 1 to 10. A simple way to do this would be to divide the range into 10 equal parts and map each to a single number. The diagram below demonstrates this:

Hash Functions are typically used in applications where data storage and retrieval requirements expect a constant time complexity. A good hash function is one that uniformly distributes data into different buckets.

Specialized hash functions that guarantee certain security properties are widely used in the field of cryptography and information security. For example, applications that need to verify the integrity of confidential data use a *cryptographic* hash function.
Password verification and digital signature schemes also rely on such functions.

Such functions are often called *one-way* functions – it is practically infeasible to invert them, i.e., provided the output of the hash function, it should be infeasible to arrive at the input that produced the given output.

*Pre-image resistance*

Reversing a hash function to obtain the original string should be impossible.*Weak-collision resistance*

Given the input*i*, it should be difficult to find another input_{0}*i*, such that the hash of both values is the same._{1}*Strong-collision resistance*

It should be difficult to find two different messages with same hash value.*Determinism*

The same string should generate the same hash every single time.*Non-Predictable*

There should be no way to predict the hash from a password.*Diffusion*

A small change in the original string should lead to a big change in the resulting hash.

A slightly modified variant of FNV was used as the default hash function in *Python*.

It is widely used in *zlib* compression library.

RIPEMD is used in *Bitcoin* and related applications.

Scrypt is used as a password-based key derivation function for password hashing.

In many programming languages, a hashcode of an object is used to determine if two objects are equal.

Hash functions are employed in order to quickly verify if the element is a member of the set.

This is one of the most common applications of hash functions – it certifies to the user that the data is unchanged. However, it does not guarantee the originality of the file, so the attacker could potentially change both the file and the hash.

In the simplest verification scheme, the passwords are stored as a one way hash. When you enter your password, it is hashed and then the two hashes are compared to each other.

RELATED TAGS

general

community creator

CONTRIBUTOR

Anjana Shankar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses