How does hashing work?

In the previous lesson, I introduced the concept of hashing and relevant terms. Now, let’s learn how it works!

Hashing is a mathematical operation that is easy to perform, but extremely difficult to reverse.

The hashing process turns a piece of data into binary code, which is just a bunch of 0s and 1s.

Then it breaks up the numbers and applies some secret “jumbling”, which is done by something called the “hash function”.

How does hashing work in crypto?

When used in Bitcoin and other cryptocurrencies, the end result is typically a 64-digit long string of numbers and letters.

Because the conversion is done by a cryptographic algorithm (the “hash function”), the jumbling formula is unknown so the 64-digit string can’t be reversed.

Hashing Concept

A string is a sequence of characters.

Strings are like sentences. They are formed by a combination of characters.

String

Think of a hash as a bunch of random letters and numbers.

A unique piece of data will always produce the same hash.

For example, every time the string above is run through the hash function, it will always produce the same hash.

But what happens if we make just a tiny change to the string? (Highlighted in yellow.)

String Change

The sentence ends with a question mark instead of a period.

Even though it was a TINY change in the sentence, the hash is TOTALLY different.

 

You can see how using hashes can be used to detect tampering since even a small change to that input to the hash function results in a totally different output.

 

It’s very important you remember this point because, in a later lesson, you’ll see how this is used to prevent previous transactions from being tampered with.

The hash function is ONE-WAY only.

The hash function is ONE-WAY only.

You can’t take an existing hash and try to reverse it to find the input string.

So if all you know is the hash, there’s no way to know what the original input is. You can’t “reverse engineer” or hack the hash.

Lastly, the length of the output (the “hash”) does NOT grow with an increase in information in the input. A hash function takes input data of ANY length and returns a value that has a FIXED length.

Hash Output is Fixed

If you put the entire text of a Harry Potter book, which has over 76,000 words, the hash output will STILL only be 64 characters long.

 

And again, if you misspell even a single letter in the Harry Potter book, and ran it through the hash function,  it would produce a totally different hash from above.