Before diving into the subject of Bitcoin mining, we need to take a quick detour and learn about a certain concept that’s foundational to cryptocurrencies.
In order to truly understand how Bitcoin and other cryptocurrencies work, it’s crucial to first understand the concept of “hashing“.
When you see the word, “hash”, some folks might think of hash browns, a popular American breakfast food, while other folks like Snoop Dogg, might think of the cannabis concentrate product. 🌿
In this lesson, I will be talking about a different kind of hash!
It’s a technical concept, but one you must be familiar with so I will break it down for you nice and easy.
Being familiar with the concept of hashing is also needed to understand how Bitcoin mining works (which is the next guide) so please don’t skip over these lessons. 👁️
What is hashing?
Hashing is a method of cryptography that converts any form of data into a unique string of text of fixed length.
Cryptography is the practice and study of techniques for secure communication from outside observers. In the internet era, cryptography is used to protect computer information or “data”.
If it wasn’t already obvious, the “crypto” in cryptocurrencies stands for cryptography.
Hashing is a fundamental part of cryptography. And plays a huge role behind the “crypto” in cryptocurrencies.
In simple terms, hashing means inputting text of ANY length through a hash function which produces an output of a FIXED length.
Any piece of data can be “hashed”, no matter its size, type, or length.
The hash that is produced is always the same length.
In the examples below, using the SHA-1 hash function, regardless of the length of the “input”, the “output” is always 40 characters long.
Here’s a quick comparison of the three examples:
Input | Hash |
---|---|
Hello | f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 |
BabyPips.com | 8c8780d0b70c5ef42a534846cc042629cf07a440 |
I | ca73ab65568cd125c2d27a22bbd9e863c10b675d |
Notice that even though the “inputs” varied, all three hashes were still 40 characters long.
In this specific example, the fixed length is 40 characters long, which is determined by the specific hash function used (“SHA-1”), which will be explained later.
For now, just know that other hash functions may output different fixed lengths. Most have fixed lengths that are longer than 40 characters.
A hash acts as a digital fingerprint.
A unique piece of data will always produce the same hash.
For example, if you run “Hello” a million times through a hash function, the above hash is what will appear a million times.
For the word, “Hello”, its SHA-1 hash will always be:
f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0
And only “Hello” will ever produce that hash.
Any change to “Hello” even if it’s just changing it to “hello” and the hash function will produce a totally different hash value.
This is why hashes are known as digital “fingerprints“.
Just like your fingerprint is unique to you, a hash is unique to a specific input of data.
A hash can’t be reversed.
The INPUT into a hash function is called a “preimage” But to keep things simple, I just stick with “input”.
The OUTPUT of the hash function is called “hash value” or “digest” or simply as a “hash”.
A hash function is designed to act in a one-way manner.
Since a hash function is a one-way function, the output, the “hash”, can’t be used to reveal the input, the “preimage”.
This means that if all you see is the hash, you will NOT be able to decipher the original data (the “preimage”) that the hash represents.
Hash functions produce irreversible hashes.
Irreversible means that if you only had the hash you couldn’t use that to figure out what the original piece of data was. This allows the original data to remain secure and unknown.
What is a hash function?
A hash function is a mathematical operation that converts input data of arbitrary length into an output of fixed length that is executed using a certain algorithm.
An algorithm is just a step-by-step set of instructions for performing calculations that are done by a software program.
It doesn’t matter if the input is a single letter, a word, a full sentence, a page from a book, or an entire book, That’s the arbitrary part.Each input will produce a unique output expressed as an alphanumeric string of fixed length.
Alphanumeric just means that something consists of both letters and numbers.
A useful hash function conceals any clues about what the input may have looked like.
For example, it needs to be impossible to determine whether the input was long or short or contained numbers or letters. Also, changing just one character in the input should result in a radically different output.
Popular Hash Functions
All hash functions work in a similar manner. You input data, and the hash function “scrambles” the data and outputs a hash.
Common hash functions include:
- MD-5: Message Digest 5 (MD5) is a common hash function. In the past, it was considered secure but nowadays, hackers have discovered how to decode the algorithm and are able to do so in seconds.
- SHA: Secure Hash Algorithm (SHA) is another type of hash function. There are several variations of SHA grouped into four families: SHA-0, SHA-1, SHA-2, and SHA-3: In general, the higher the number, the more recent the release and the more secure the algorithm.
For our purposes, the only hash function you need to know about right now is the Secure Hash Algorithm (SHA). More specifically, the SHA-2 family since it contains a special member in the family named SHA-256.
SHA-256 is a hash function that converts a string of text into another string that is always the same length: 64 alphanumeric characters long. This is equivalent to 256 bits, which is where the “256” in its name comes from.
It’s special because it’s the hash function used in several parts of the Bitcoin system, which you’ll learn about in later lessons. For now, it’s important to just know that SHA-256 is a type of hash function and the one used by Bitcoin.
Whether the input is a page from a Harry Potter book or the entire series of Harry Potter books. the output of the SHA-265 hash function will always be the SAME length displayed as 64 alphanumeric characters.
Let’s now take a look at how hashing works in crypto.