Javatpoint Logo
Javatpoint Logo

Blockchain Hash Function

A hash function takes an input string (numbers, alphabets, media files) of any length and transforms it into a fixed length. The fixed bit length can vary (like 32-bit or 64-bit or 128-bit or 256-bit) depending on what hash function is being used. The fixed length output is called a hash. This hash is also the cryptographic byproduct of a hash algorithm. This is illustrated as below.

Blockchain Hash Function

The hash algorithm has certain unique properties:

  1. It produces a unique output (or hash).
  2. It is a one-way function.

In the context of cryptocurrencies like Bitcoin, the blockchain uses this cryptographic hash function's properties in its consensus mechanism. A cryptographic hash is a digest or digital fingerprints of a certain amount of data. In cryptographic hash functions, the transactions are taken as an input and run through a hashing algorithm which gives an output of a fixed size.

SHA-256

A Bitcoin's blockchain uses SHA-256 (Secure Hash Algorithm) Hashing algorithm. In 2001, SHA-256 Hashing algorithm was developed by the National Security Agency (NSA) in the USA.

How does the hashing process works?

For this hash function, we are going to use a program developed by Anders Brownworth. This program can be found in the below link.

Anders Brownworth Hash Program: https://anders.com/blockchain/hash.html

Blockchain Hash Function

If we type anything in the data section, you will see that with every single character as we build you have a cryptographic hash equivalent in hash section.

For example: We have type in data section: This is a great tutorial.

It will generate the corresponding Hash:


Blockchain Hash Function

Now if we change the Text: "This is a great tutorial." to "this is a great tutorial."

You will find the corresponding Hash:

In the above, you can see that we have changed only the first character case sentence from capital "T" to small "t" and it will change the whole Hash value.

Note: If we write the same text again in a data section, it will always give the same output. It is because you are creating a message digest of that one's specific amount of data.

Since the Hash function is a one-way function, there is no way to get back entire text from the generated hash. This is different from traditional cryptographic functions like encryption where you can encrypt something using the key and by using decryption you can decrypt the message to its original form.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA