Randomness and Cryptography
Tags: productivity, opensource, blockchain, cryptography
Published: 2022-02-20 14:04:09

### Hey everyone👋
  I am back with `The ‘Random’` series! One of my most loved and my personal favourite as well💗.
This series has overall got almost 4K+ views🤩 on various platforms like [Dev Community](https://dev.to/prakhart111), [HashNode](https://prakhartandon.hashnode.dev/) and [TealFeed](https://tealfeed.com/prakhart).

I will recommend you to read the previous article before reading this one👉 [Is random() really random?](https://dev.to/prakhart111/are-random-really-random--23if)

### So let’s dive in!!!!!!

Before diving into the cryptographic aspect of randomness, we first need to understand what actually cryptography is and how it works.

**So Wikipedia says**
> Cryptography, or cryptology, is the practice and study of techniques for secure communication in the presence of adversarial behaviour.

...And that was a very bookish type of definition.

Okay so cryptography is basically some sort of encryption for the data being transferred, that means only the sender and receiver can view the data or the message...  and ideally no one else, not even ZuckerBurg (lol🤭).
And yeah its actually (kind-of) more ideal version of what WhatsApp claims to provide “END TO END ENCRYPTION”.

#### NOTE
> Cryptography is a subject that involves a-lot of high-end mathematics, and hence, I will try to avoid those complex expressions and keep it as simple as it can be.

This is closely related to encryption, which is the act of scrambling ordinary text into what's known as cipher-text and then back again upon arrival.

Some very common examples of encryption can be:
- Encryption over the internet like the SSL.
- Wireless 4G LTE network uses 128-bit Advanced Encryption Standard (AES) and SNOW3G
- Your Internet banking, cards, UPI payments etc.
- Encryption in your computer like storing passwords, files etc.

If you have ever heard of the famous Ceaser Cipher, you will probably be able to connect with the idea of cryptography.
[If you haven’t read it here.](https://www.sciencedirect.com/topics/computer-science/caesar-cipher)

### How Encryption works

In case of encryption, a given algorithm will always transform the same plain-text into the same cipher-text if the same key is used.
**Key** is basically some number, that is used while encoding and decoding.

_So let’s have an example._

Say we take KEY = 2 and we decided to encode our message in such a way that every English alphabet is replaced by the  ‘KEY’th alphabet.
That means in our example
- ‘A’ to be replaced by ‘C’
- ‘B’ to be replaced by ‘D’ and so on.

#### **And a simple assignment👇 !!**
_Comment down what is the below message based on the above description(Key=2)._
> **Kpetgfkdng Kpfkc!**
_Note: Special characters remain the same in Caesar Cipher._

So this can be the simplest form of encryption.

There are two types of cryptography symmetric and asymmetric.

#### Symmetric Cryptography
With symmetric cryptography, the same key is used for both encryption and decryption. A sender and a recipient must already have a shared key that is known to both.
So just have a thought ... you are also sending the decryption key via the same channel, that can obviously be intervened I mean hackers are damn smart nowadays!

Although any hacker won’t be interested in reading your efforts and super fast replies towards your crush even after getting ignored, so you can relax.......emotional damage😫 (to me as well).

#### Asymmetric Cryptography
So yes, these security concerns lead to the development of next type that is **Asymmetric**.

Here, we have two different keys, **PUBLIC KEY** and a **PRIVATE KEY**.

Private key as the name suggests, is always private to whom it belongs, and his public key is available to all. Data encrypted with a public key may only be decrypted with the corresponding private key.

#### Let’s have an example:
Suppose you are Raju want to send a message to your friend Baburao about a great financial scheme.
So you need to have his public key, and encrypt the message using it and send it to him.

Only Baburao can decrypt the message, as only he has his private key. 

And similarly any data encrypted with a private key can only be decrypted with the corresponding public key.


Let’s dive even deep with a easier real-world example.

So basically🤔, we want an encryption method, that is easy to do on one side, but difficult from the other side i.e, encrypting is easy but decryption without required information is very difficult.

Here we can use a simple yet great mathematical trick (that actually powers the modern world, not as it is though) is **Prime Numbers**!

Say you multiply two prime numbers 13 and 67 that would be 871. Very Simple..isn’t it.

Now have a look in the opposite direction.

You have given 871 and you need to find exact those prime numbers we used to encrypt it.

This will take you a while, I mean you will look at different possible prime combinations as so on. But now, what if I say those numbers will be something **huge** like 10^20 or 10^30 !!!
😯
Multiplication(encryption) would be fairly easy, but decryption will take a-lottt of time!!

### Now let’s get back to the ‘Random’ Numbers.
The "key" has to be random! Randomness as it is used to generate session keys.

> The more random the numbers, the more secure the cryptographic system.

And here comes the problem that we discussed in our previous article, computers cannot provide pure randomness. 

Hence we use "cryptographically secure" pseudo random number generator, that are based on external entropy, the best source of which is Quantum Physics. Quantum Random Number Generators (QRNGs) are able to provide highest possible randomness till date.

In its [latest report looking at quantum computing](https://www.idquantique.com/the-importance-of-randomness-in-a-quantum-world/#:~:text=Randomness%20(entropy)%20is%20the%20cornerstone,use%20pseudo%2Drandom%20number%20generation.), **the IBM Institute for Business Value** highlights the potential quantum technologies have to become ‘a double-edged sword’; one that will expand computing power and offer opportunities for improving cyber-security, whilst exposing vulnerabilities in current encryption methods.

####Hashing
There exists another similar term "HASHING". Hashing is the process of converting the information into a unique text using a hash function. The original information cannot be retrieved from the hash key by any means.
Most popular algorithm for this is `SHA-256`. In this, no matter how large your input data is, the resulting Hash will always be of 256 characters.

> If you people are interesting in knowing about hashing more, let me know in the comments below.

#### Here are some resources that you can have a look at to gain more insights about Cryptography.

- [Cryptography Concepts every developer should know by FireShip](https://youtu.be/NuyzuNBFWxQ)
- [A TED from James Lyne :Power of randomness](https://youtu.be/SAAflrIp__E)

I found the below ones bit advanced.
- [QRNG White Paper](https://marketing.idquantique.com/acton/attachment/11868/f-0226/1/-/-/-/-/What%20is%20the%20Q%20in%20QRNG_White%20Paper.pdf)

- [True Randomness](https://www.design-reuse.com/articles/27050/true-randomness-in-cryptography.html)



###Thanks for reading😌!
#### If you loved the article please share it😉, it takes a-lot of efforts and time making `The Random` series.



###Want to connect?
[You can connect with me here](https://linktr.ee/prakhartandon)