# Blockchain Hash Function Background

October 31, 2017

Before we learn how we can seal the page, we need to know how the seal works, in general. And as a pre-requisite, we will introduce…

# The Magic Machine

Imagine a machine surrounded by thick walls. If you send a box with something inside it from the left, it will spit out a word containing something else.

[Jargon Box] This machine is called ‘Hash Function’. So, for today, these are ‘The Magic Machines.’

The Magic Machine (aka Hashing Function)

Suppose, you send the number 4 inside it from the left, we’d find that it spat out the following word on its right: dcbea.

How did it convert the number 4 to this word? By using a mathematical function to do so. Moreover, it is an irreversible process. Given the word, dcbea, it is impossible to tell what the machine was fed on the left. But every time you’d feed the number 4 to the machine, it will always spit out the same word, dcbea.

hash(4) == dcbea

Let’s try sending in a different number. How about 26?

hash(26) == 94c8e

We got 94c8e this time. Interesting! So, the words can contain the numbers too.

# Predicting the input

Let’s ask the following question now:

“Can you tell me what should I send from the left side of the machine such that I get a word that starts with three leading zeroes from the right side of it? For example, 000ab or 00098 or 000fa or anything among the others.”

Think about the question for a moment.

You’ve learned that the machine has a property that we cannot calculate what we must send from the left after we’re given the expected output on the right. With such a machine given to us, how can we answer the question?

Here’s a simple method — why not try every number in the universe one by one until we get a word that starts with three leading zeroes?

Tries everything to calculate the input

Being optimistic, after several thousand attempts, we’ll end up with a number that will yield the required output on the right.

It was extremely difficult to calculate the input given the output. But at the same time, it will always be incredibly easy to verify if the predicted input yields the required output. Remember that the machine spits out the same word for a number every time.

How difficult do you think the answer is if given a number, say 72533, you’re asked the question, “Does this number, when fed into the machine, yield a word that starts with three leading zeroes?”

All you need to do is, throw the number in the machine and see what did you get on the right side of it. That’s it.

The most important property of such machines is that :

Given an output, it is extremely difficult to calculate the input, but given the input and the output, it is pretty easy to verify if the input leads to the output.

We’ll remember this one property of the Magic Machines (or Hash Functions) through the rest of this guide.