0 50

If you are like me and you like to understand how stuff works, then this article is for you, in this post, I will be explaining the different algorithms used in the crypto space, of course not all, but I will be able to cover the basic ones, enough to make you understand why some things are the way they are, and also helps your problem solving ability.

Disclaimer: I am not a cryptologist neither am I an expert in this field, so I might use some words loosely, don’t be offended, and also this is not an exhaustive list, I might miss some but I will surely update this lists continuously.

### Cryptographic Hash Functions

The first algorithm we will be looking at is the hash function, as this is the basis of the uniqueness of bitcoin addresses created.

A hash function is a mathematical function which takes an input (message) and returns a fixed sized alphanumeric string.

a hash function has the following characteristics:

• It is easy to compute a hash for any given input string
• It is extremely difficult to compute the exact string that has given the hashed output: This means that it should be impossible to reverse-engineer the hashed output to get the input string even if the algorithm that is used in developing the hash is known, for example:
if I have an input 2 + 2 +5 = 9, now given the output 9, for me to tell what numbers were added to arrive at 9, I will have to iterate over 9C1, which is still solvable considering the simplicity of the output, however, what happens when I have an output like 92830384059555686468684884784, its going to be extremely difficult to compute, and it is known that some of the best hash functions will take millions of years to decrypt even by a quantum computer.
• A hash function should be able to take an input string of any length and turn them into an output of fixed length: meaning that if I have an input of “Hello World” or “Hello this great looking awesome world” the output should have a fixed length for the two strings even though they are two different strings with different lengths

Bitcoin makes use of the SHA256 which stands for Secure Hash Algorithm 256bits, although this algorithm was originally developed by the NSA, it has been publicly vetted and verified.

### Merkle Tree

Now, having understood what hash function is, you will need to apply that knowledge with Merkle Tree. The Merkle Tree is being used in cryptocurrencies to securely verify and validate transactions, with this cryptocurrency use it to ensure consistency and data integrity. because once any change is being made to one node in the tree, it affects all the nodes as the values changes.

How Merkle trees work

Merkle trees are created by repeatedly hashing pair of nodes until there is only one hash left, the one left is called the Merkle root, a node could contain any type of data, but here, let us take a node to contain transactions, the first step is to use our hash function (SHA 256) to hash each transaction, for example: if the raw transaction data looks like this:

`0200000000010111b6e0460bb810b05744f8d38262f95fbab02b168b070598a6f31fad438fced4000000001716001427c106013c0042da165c082b3870c31fb3ab4683feffffff0200ca9a3b0000000017a914d8b6fcc85a383261df05423ddf068a8987bf0287873067a3fa0100000017a914d5df0b9ca6c0e1ba60a9ff29359d2600d9c6659d870247304402203b85cb05b43cc68df72e2e54c6cb508aa324a5de0c53f1bbfe997cbd7509774d022041e1b1823bdaddcd6581d7cde6e6a4c4dbef483e42e59e04dbacbaf537c3e3e8012103fbbdb3b3fc3abbbd983b20a557445fb041d6f21cc5977d2121971cb1ce5298978c000000`

the hashed functioned will look like this:

B579585CA762CB2F17BDEC8C6698C0E8A3BC3D981397CB5DE09C1710F9C7DE51

These hashes are then organized into what is now called the Merkle tree, so for each transaction done, the hashes are paired, concatenated and then hashed together, this is done for each output of our transactions until something like a tree below is formed

You might also like