The Science Behind Cryptocurrencies Cryptography

In this guide, we will be going deep into symmetric and asymmetric cryptography and the science behind cryptocurrencies cryptography.

Cryptocurrencies like Bitcoin and Ethereum use a peer-to-peer decentralized system to conduct transactions. Since the entire process is online, there are fears that the transactions maybe volatile and hackable. What we are going to see in this guide is how cryptocurrency uses cryptography to make their transactions extremely secure.

Digital Signatures

One of the most important cryptographical tools that are used in cryptocurrency is the concept of signatures. What is a signature in real life and what are its properties? Imagine a paper that you have signed with your signature, what should a good signature do?

In the real world, however, no matter how intricate the signature, there are always chances of forgery, and you cannot really verify signatures using simple visual aids, it is very inefficient and non-reliable.

Cryptography gives us a solution to this by means of digital signatures which is done via the use of keys. So, what are keys? And how are the used in the blockchain? Before we explore those, it is important to know more about basic cryptography.

Cryptography is a method of using advanced mathematical principles in storing and transmitting data in a particular form so that only those, for whom it is intended for, can read and process it. Cryptography has been used for thousands and thousands of years by people to relay messages without detection. In fact, the earliest use of cryptography was seen in the tomb taken from Old Kingdom in Egypt circa 1900 BCE. Cryptography has existed in the modern society through one way or another.

Encryption is one of the most critical tools used in cryptography. It is a means by which a message can be made unreadable for an unintended reader and can be read only by the sender and the recipient. In modern technology, there are three forms of encryption that are widely used, symmetric cryptography, asymmetric cryptography, and hashing.

Symmetric Cryptography

Symmetric cryptography is the earliest known cryptographic method known to man. The concept is very simple and if we were to break it down to steps, this is what it will look like:

If we were to show a visual representation of the process, this is what it will look like.

Image credit: SSL2BUY

The are two types of symmetric cryptography:

Stream cipher basically means using a fixed key which replaces the message with a pseudorandom string of characters. It is basically the encryption of each letter one at a time.

We are going to discuss 3 kinds of stream ciphers in this guide to give you an idea of how stream ciphers work:

One-time pad with alphabets

For doing this encryption we need to have a key which has the same number of characters as the message and it must be used one time only (hence the term one-time pad).

Suppose for this example we are going to send a message, MEET ME OUTSIDE to our friend Bob. But we dont want anyone intercepting our message. This is why, Bob and us have decided to use a one-time pad which goes like this:

B D U F G H W E I U F G W

As you can see, the pad has the same number of characters as the message as well, i.e. 13.

Now, this is a very simple example of the one-time pad, we are using this because we feel it is the best example to use to understand this tactic.

Now, one more thing you need take note of, every alphabet will be replaced by its numeric equivalent in during the process.

The numerical mapping goes like this:

During the process, there will be 6 pieces of data that we need which are: Basically, the numerical equivalent of each alphabet. Ok, now that we have built the foundations, lets move on to the actual process.

So, we need to send the message MEET ME OUTSIDE and we need to use the one-time pad to encrypt it.

The encryption process

So, lets start off by putting in the message in the OM

We put the message MEET ME OUTSIDE in the OM row.Ok, so what happened here?

Next, we used the numerical mapping table to get the numerical equivalent of each alphabet. So, lets refer to the mapping table and see what we get:

In the OTP row we put in the key that we were already given which is, in case you have forgotten, B D U F G H W E I U F G W.Its just simple substitution, we will take these values and put it in NOM row.

Now, in the NOTP row we used the same number mapping table and found the equivalent numerical values of the key which are:

1, 3, 20, 5, 6, 7, 22, 4, 8, 20, 5, 6, 22.

In the new row, for the Numerical cipher text (NCT) we add the NOTP and NOM and mod the result by 26 to get our NCT.

So, finally the message MEET ME OUTSIDE turns into a pseudo-random series of characters N H Y Y S L K Y B M N J A.Thats how you find the values for NCT and then you use the mapping table and find the corresponding alphabets which are: N H Y Y S L K Y B M N J A.

That is how the encryption process works.

Now we will see how we can decrypt the message using the exact same key.

Lets see the data that Bob has with him:

So, how will he decrypt the message using this data?

So, lets see how the NOM calculation work?

Now, if we map the NOM to its alphabetical equivalent using the mapping table then we get:

MEET ME OUTSIDE

And just like that, the message is encrypted and decrypted using the same key.

One-time pad with XOR gate

XOR or Exclusive OR is a logic gate. What is a logic gate? A logic gate usually takes in 2 inputs and gives out 1 output. The inputs and outputs are binary values, meaning they can be 1 or 0. A XOR logic gate takes in 2 binary inputs and gives out a high output ONLY when the inputs are different. Meaning, if A and B are inputted to a XOR gate then the out C will be 1 ONLY when A is not equal to B.

The XOR gate looks like this:

Image courtesy: Wikimedia

This what the XOR truth table look like:

Suppose you have a plain text data which you want to send to your friend Alice. First, youll convert it to its binary form. Suppose the message that you have is this: 00011110

Now you have the key, the key that you share with your recipient and suppose you have passed the key through an algorithm which gives you the equivalent binary result: 01001010.

So now that you have the key, you are going to XOR each corresponding individual bits to get the resulting cipher text output.

Cipher Text = Plain Text XOR Key

So if you XOR both the data the key that you will get is:

01010100

This is the cipher text that Alice will get from you.

The decryption process

So now, how will Alice decrypt your message and retrieve the original one?

This is the data that she has:

So what is she going to do? It is simple.

She will simply XOR the key and the cipher text and she will retrieve the original message! See for yourself:

And just like that, she will retrieve the original message.

Linear feedback shift register

What is a linear feedback shift register? It is a function whose future output completely depends on its earlier (or current) state. This will become clearer as you keep reading so dont get scared off!

The idea of this style of a stream cipher is to predetermine a key with your recipient which will be a linear feedback shift register function which will be used by you to determine the code. Suppose you spoke to your friend Bob and determined that this is the formula that you both want to go with (credit to Daniel Rees from Youtube for this formula).

And lets also assume that prior to sending this message you and Bob determined that E(1) = 2 and E(2) = 4.

Now you can see that in this equation, all future outputs are dependent upon the previous outputs.

So, suppose the message that you want to send to Bob is MEET ME. Since there are 6 characters, we need to determine 6 values of E() to act as key. We already have predetermined the values of E(1) and E(2). Now we need to calculate E(3) to E(6).

So, now that we have the keys, lets start the decryption.

The encryption process

So now that we have the key and message, lets create the table:

To get the numerical cipher text, you add the key and the corresponding numerical value of the alphabet that you map from this table that we have already seen before:

Now, to get the numerical value of the cipher texts, add the key and the numerical value of the original message and mod with 26.

So you get:

Now use the mapping table again to find the corresponding alphabets and you get OIORSO. Thats the encrypted message.

The decryption of this message is really hard especially if you dont have the key. An expert might spot a pattern though. You will need computers to beak this code.

The Rivest Cipher 4 of the RC4

The A5/1

So, that is pretty much it about stream ciphers, time to move on to block ciphers.

Block ciphers are a form of symmetric cryptography which uses a key of a fixed length to encrypt a block of fix length. Lets start by checking out a very common substitution cipher that you must have seen before:

So, if someone were to tell you that they got a message which says EFBD and wants you to decrypt it and get the original message instead, how will you do it?

You will simply see the table, see which alphabets correspond to which and then simply substitute right? So EFBD is the cipher for FACE.

Follow this link:
The Science Behind Cryptocurrencies Cryptography

Related Posts
This entry was posted in $1$s. Bookmark the permalink.