Blog‎ > ‎Miscellaneous‎ > ‎

### Hash Functions Explained In 2 Minutes!!

posted Sep 4, 2017, 12:53 PM by Rohit Bhaskar   [ updated Sep 4, 2017, 12:55 PM ]
 We can see here that the grumpy cat has been transformed into an even grumpier and unrecognizable sequence of letters and numbers. This is what will happen to you if you walk through a hash function, it changes you for good. A hash function is a non-invertible mathematical function that converts a numerical input value into another compressed numerical value. The input to the hash function is of arbitrary length but output is always of fixed length.Hash functions are sometimes referred to as compression functions also as the hash is much smaller than the input data.At the heart of a hashing is a mathematical function that operates on two fixed-size blocks of data to create a hash code. This hash function forms the part of the hashing algorithm.The size of each data block varies depending on the algorithm. Typically the block sizes are from 128 bits to 12 bits. The following illustration demonstrates hash function.This process is repeated for as many rounds as are required to hash the entire message. Schematic of hashing algorithm is depicted in the following illustration - Since, the hash value of first message block becomes an input to the second hash operation, output of which alters the result of the third operation, and so on. This effect, known as an avalanche effect of hashing. Avalanche effect results in substantially different hash values for two messages that differ by even a single bit of data. Hash function in Bitcoin In the bitcoin protocol, hash functions are part of the block hashing algorithm which is used to write new transactions into the blockchain through the mining process. In bitcoin mining, the inputs for the function are all of the most recent, not-yet-confirmed transactions (along with some additional inputs relating to the timestamp and a reference to the previous block). We can see from the above diagram that if we change even one byte of information the hash function is drastically changed, this ensures that no two inputs have same hash functions. Thus a bitcoin block can be verified by checking the hash vape of the block along with the hash values of previous blocks thus ensuring its authenticity.Hash functions have been researched and developed on for many years now. The bitcoin uses the SHA - 2type of Hash function. SHA - 1 was so powerful that Google’s supercomputer took three years to find two different inputs with the same hash function (God level stuff), and the SHA - 2 has been undefeated to date !!- Suyash Junnarkar