## Bitcoin technology Explained

Industry experts are very enthusiastic about Blockchain. Articles, blogs are being written about how it will transform Fintech. Innovative solutions based on blockchain are a reality in areas other than crypto-currencies. By understanding the design elements of Blockchain and Bitcoin many more innovative solutions can be created.

Knowledge of the basics of cryptography is very important to make sense of it all, hence we delve into it first.

### Cryptographic hash function

If you provide a stream of bytes to a cryptographic hash function, it generates a number called hash (sometimes referred to as digest). The following properties make it a very useful tool for Blockchain:

- It is impossible to guess the generated hash value for a stream of bytes. To get the hash value, one has to run the algorithm, there is no shortcut.
- For a given input it always generates the same hash value.
- It is infeasible to deduce the input based on the hash value. That means it is an irreversible mathematical function.
- No two different stream of bytes result in the same hash value. Even a small change in the input stream generates a totally different number.
*(More in the comments section below regarding this.)*

The two main hash functions used by Bitcoin are:

- SHA-256 (returns 256 bit unsigned integers)
- RIPEMD-160 (returns 160 bit unsigned integers)

Sample hash values:

Input | SHA-256 | RIPEMD-160 |

Hello world | 64ec88ca00b268e5ba1a35678a1b5316d212f4f3534a8aeca37f3c | dbea7bd24eef40a2e79387542e36dd408b77b21a |

Hello world. | aa3ec16e6acc809d8b256abfd2f1b441cb51574933f3d4bd115d11 | 6ad34a17d22d67a7ab02710ae9eb6f282cb1d787 |

Unrelated, totally. | 2bd72f5c325b3363ef2027f30eddbc6458 | 51cb1844d22a00d5f659795e0b1c339c6fa1a8bc |

There are two things we observe from the table above:

- With a slight change in input, the hash values change dramatically and by looking only at the hash values, one cannot conclude that the first and second are even closely related.
- The values mentioned are actually text strings and do not look like numbers, although we expected them to be numbers.

They are actually numbers, represented this way to reduce the size of the presented text. For example, binary representation of the number 255 is ‘11111111’. Decimal representation is ‘255’. Hexadecimal representation is ‘ff’ or ‘FF’. The representations in the table above are hexadecimal representations of 32 byte and 20 byte numbers. If you notice the size of the representation reduces as we move from binary to decimal to hexadecimal representations. There are more compact representations commonly used in the industry like base36 encoding (eg. a PNR of an airline ticket with numbers and all the alphabets included in the representation).

Bitcoin makes extensive use of Base58 and Base58check encoding. These are much more compact form of representing the same data (essentially 32 byte and 20 byte integers).

## Public-Key Cryptography

Elliptic Curve Cryptography is used extensively in Bitcoin. ECC is a form of public-key cryptography also known as asymmetric cryptography. In this, a sender encrypts a stream of bytes using a public key. The encrypted data seems gibberish to everyone. Only the one in possession of the corresponding private key can decrypt the data and get the original data.