The hash function

Before moving on with the mathematical problem, let's first focus on the rule given by the wall, the so-called hash function.

A hash function is a mathematical function that transforms any chain of characters or numbers into a fixed-length chain of characters. It turns data into a digital fingerprint called a hash. For example, if I enter euclide (7 characters) into the hash function called SHA-256, it will return the 64 characters hash: E0F4C627CD4D365EE9760BAA6A1CD35CA26CF7252F6EB25C0DC7B4C3E2718A20.

SHA stands for Secure Hash Algorithm and is a set of cryptographic hash functions designed by the US National Security Agency. SHA-256 means that it is a hash function producing a 256-bit-long output.

Now, if I input into the same SHA-256 hash function the entire Wikipedia's Bitcoin page description, it will return: D5752C643EC97DC0FF32AE74FF2F2079043A8AB0191C51AEFDE09EDE0C757EE6.

It returns 64 characters—all of the timewhatever the length of the input is. 

The hash function is deterministic: it is always the same output for the same input.

The following diagram depicts the process explained in this section: 

The principle behind a hash function is, when you know the output, it is very hard to find the input because the reverse action is not possible. That is, knowing the digital fingerprint of data does not reveal that specific data. You cannot guess that I entered euclide if I tell you that the output is E0F4C627CD4D365EE9760BAA6A1CD35CA26CF7252F6EB25C0DC7B4C3E2718A20. However, when knowing the input, it is very easy to find the correct output. Indeed, you can easily verify that euclide returns the hash E0F4C627CD4D365EE9760BAA6A1CD35CA26CF7252F6EB25C0DC7B4C3E2718A20, just by entering it into the SHA-256 hash function.

You can try this yourself on your device. Try typing euclide on the following website: https://passwordsgenerator.net/sha256-hash-generator. You should find the same chain of characters as mine.

If we return to Village Beta, you might have understood where this is going:

  • The reference number, 0
  • + the timestamp of the page, 2018/06/25, 03:25 PM
  • + the transactions (the data written in one page of the book)
  • + the nonce (number X)
  • = return the hash of page #1 (an output number following the rule: a number starting with two leading zeros)

The preceding equation can be pictured like this: 

Consequently, to find the output number (a number starting with two leading zeros, or the hash of the page), every villager will have to try several inputs for number X for the equation to return a number respecting the rule.

It is as if I asked you: using the SHA-256 hash function, can you find an output number starting with two leading zeros? How many inputs will you try before finding a correct output?

You can also try this exercise on your device, using this website: https://passwordsgenerator.net/sha256-hash-generator.