In this lesson, we are going to talk about hashing. It's certainly not easy, but we won't let that scare us away. Here we go.
✔️ Hashing is converting a collection of data into a code, the hash, using a predetermined calculation.
✔️ Hashing is often used to secure passwords so that only the user can read them and to compare checksums when downloading files.
✔️ Digital signatures use hashing for authentication, where the recipient needs the private key to decrypt the message.
✔️ Cryptocurrencies use hashing for mining, where computers must use their computing power to solve puzzles to receive rewards.
Hashing is the process of converting a collection of data by a function into a code, the hash.
First, let's explain what a hash is. A hash is an outcome of some kind of calculation based on predetermined conditions. A hash consists of a series of numbers and letters.
We will give an example of hashing to make it a little more visual. With SHA (Secure Hashing Algorithm) 256, you can obtain a hash for any kind of textual information. I will create two sentences that are very similar, but whose outcome (the hash) looks very different.
The sentence "what is hashing" (the input) produces the following hash:
a85eaf708bd0da1c0b7206ab8d69c30403b34be19588b71702d420ff9b21f09c (the output)
The phrase "What is hashing" produces a very different hash:
SHA-256 produces a 256-bit long hash (64 characters).
By the way, hashes work in one direction. You can create the hash of a sentence, but you cannot reconstruct a sentence from the hash.
A hash must be set up so that it requires unacceptable effort to guess the hash based on brute force (simply checking all possibilities 1 by 1). The more characters a hash function generates, the harder an input is to crack.
Now the idea of hashing must have taken shape in your imagination.
In general, we can say that hashing is used to secure data. It is most commonly used in IT to secure passwords.
Suppose you make up a password and have to send it over the Internet by entering it somewhere. If it is sent in plain text without encryption or hash, hackers can read what you enter there. That is why passwords today are hashed so that only the user can read what they enter.
Hashing can also be used when downloading files. You first calculate the hash of the file before downloading it, then see if the so-called checksum is the same. If both values are the same then the file is the original. Very handy if you don't want viruses or Trojan horses passing through the ports.
A well-known phenomenon from the crypto world is the digital signature. Here you have a sender and a receiver. A hash is made of a message. Without the private key, the message cannot be read. The receiver of the message then needs the secret key to decrypt the message. If the hash of the message matches the hash that can be calculated with this key then the message is the same as the original message.
In cryptocurrency, they work with the private key and the public key to display your address (public) or determine whether you can spend this amount of money (private key).
It's also used for personal data. When you order things online in a store you first create an account. Most of your data is hashed, so you can order anonymously, but delivery can be made to your address.
Hashing can be further secured somewhat by salt and pepper. Salt allows you to add a randomly generated number to the hash, which then creates a new hash to make it even harder for hackers to crack the code.
You can also add a pinch of pepper by adding a randomly generated string of 32 characters that is the same for all records.
When mining Bitcoin, people often talk about the hashrate. You might now be able to guess what the meaning of this is.
A computer's hashrate is the computing power it possesses to solve a difficult cryptographic puzzle. This difficult puzzle is guessing the input of a hash. The one who guesses it first gets to add a new block to the blockchain and gets the reward in the form of transaction fees and new Bitcoins.
The Bitcoin network's hashrate is the total computing power of all computers mining Bitcoin. As it gets higher, the puzzle must get harder. The fact is, a new block has to be found about every 10 minutes, according to Satoshi Nakamoto. If the computing power goes down, for example if many miners quit, then the puzzle must become easier, otherwise those ten minutes soon become 11 or 12 minutes and throw a spanner in the works.
When a new block is created at Bitcoin, it has a number of sections. Each block contains a hash of the previous block. This is to ensure that all blocks are stored sequentially.
Next, you encounter the tx_root, which is the root hash value of the Merkle tree that contains all transactions. A Merkle tree could be thought of as a collection of hashes. It is a tree diagram, where all transactions are given a hash and merged together until only one record remains with all transactions (hashes) in a single hash, the Merkle root or also called root hash. With this method, a block is much less populated than if you had to write all transactions into it, and this improves speed.
Next comes the timestamp. This contains the time when the block was created. This way, you can only create blocks forward in time.
Next comes the nonce. This is a hash that the miner has to guess to be allowed to mine a new block.
In cryptocurrency, hashing is used because it works so well and fast. Hashing also contributes significantly to security because it is a one way system. You can very easily generate a hash, but to guess the input from the hash is almost impossible.