Hashing is a cryptographic function that converts a string of characters of any length into a unique output, or hash, of fixed length. This means that no matter what combination of symbols are used as the input, they will always produce a one-of-a-kind string of digits and characters.
A Bitcoin hash looks like this:
(hash of block 540807)
- Hashing is a method for cryptographically encoding data.
- It produces a fixed-length output from any input.
- The same input always produces the same hash.
- The input cannot be reconstructed from the hash.
- Modern hash functions make it virtually impossible to produce the same output from two different inputs.
Hashing in cryptocurrencies
Hashing is an integral part of all blockchain-based transactions, including the trading of cryptocurrency. Hash functions are necessary in everything from mining blocks to signing transactions to generating private keys.
A hash function is a mathematical algorithm used to calculate the hash. Different cryptocurrencies use different hash functions but all of them follow the same basic principles of hashing.
Main properties of hashing
Hashing produces outputs of fixed length
Hashing will always produce a unique, fixed-length output from any input. Let us take a look at what that means with a couple of examples.
It’s a good day to HODL.
The entire novel Bleak House by Charles Dickens
In the table above, the SHA-256 hash function is used to generate the hashes of three different inputs. In all three cases, the hash is completely unique, but its length remains the same. SHA-256 generates hashes that are 256 bits long, usually represented as 64 symbols comprised of numbers 0–9 and letters A–F. No matter how short or how long the input is – be it a single word (hello) or even a whole novel (Bleak House by Charles Dickens) – the hash is fixed at 64 characters.
Hashing is deterministic
The same input will always produce the same output. If you use SHA-256 to generate a hash from “fun”, you will always get the output seen in the table below. Even changing one letter, however, will produce a completely different hash.
Hashing is a one-way function
It is infeasible to determine what the input was from any given output. That is to say, it is virtually impossible to reverse the hash function with contemporary technology. The only way to determine what the input was is trying out random strings until you find the right one. This method is known as brute force.
Using brute force to reverse the hash back to the original string is easier said than done. No computer in existence is powerful enough to find the solution in any reasonable amount of time, nor are we ever likely to build one that will. Even IBM Summit, currently the fastest computer in the world, capable of making several trillion calculations per second, would need many years and an astounding amount of electricity to find the answer for a single hash.
Hashing is resistant to collisions
A collision occurs when a hashing mechanism produces the same output for two different inputs. This is possible in theory for hashing, as the number of unique hashes is limited but the number of inputs is not. However, the probability of collisions is extremely small. Hashing is thus said to be resistant, but not immune, to collisions.
SHA-256, the algorithm used by Bitcoin, outputs hashes that are 256 bits long (a 256 digit-long string of 1s and 0s). This means there are a total of 2256 unique hashes that it can produce. As soon as the number of inputs is larger than the number of all possible outputs, let us say 2256+1, at least two of the inputs will have the same output – that’s a collision.
So does that mean hashing is exploitable? No, not at all. 2256 is an enormous number. In fact, enormous does not even begin to do it justice. Think about it this way: 2256 is very roughly equal to the number of atoms in the entire observable universe. The sheer size of this number means the likelihood of a collision occurring is utterly miniscule.
Hashing is fundamental for blockchain
Blockchain technology combines a range of important solutions from various fields of science. The cryptographic hash function serves as the basis for building a blockchain and harnessing those solutions. It is difficult to imagine a decentralized network that forgoes hashing entirely.