Hackernoon logoBasic of Cryptography by@gurdeep

Basic of Cryptography

gurdeep Hacker Noon profile picture


tech enthusiast. love computers , programming and hacking.

What is Cryptography?

Hi everyone this is Gurdeep , in this i am gonna talk about what is cryptography? and discuss some ancient crypto system.

So what is cryptography??

In Today's world almost every educated person might heard the word
cryptography. Some of you already know what it is but those who don't know , Cryptography is science of hiding meaning of information from non intended user or It is a practice of making communication more secure. Communication can be between humans, machines, or humans  and machines.

For example :

There are 2 humans Alex and Bob living 1000 kms away for each other. Alex want to send some secret message to Bob, so he writes a letter to Bob and send it through post-office. But the postman of that office is sneaky guy and before handing the letter to Bob he opened up the letter and read the secret and paste it as it was before not letting Bob know that letter was already read and it is not a secret anymore.

This led to a fundamental problem in communication. How to make it secure so that only intended person can read the message. As it is related to communication it is more fundamental than you think. Even in ancient times King want to send his message to knight more securely as if enemy read those message it might cause big trouble.So the thoughts and research in cryptography has very long history. Many great minds worked on this problem.

One of the most famous ancient crypto-system is Ceaser's Cipher created by Julius Ceaser. It is a very basic crypto system. Suppose Alex and Bob are working in English language and Alex want to send message "this is my secret" to Bob. He knows  that the sneaky postman will read the message if send as plain text So they decided that all letters will be send after encrypted by Ceaser's cipher.

What Alex will do is first he chose a Key, a number between 1-26 as there are 26 alphabet in English. Let the Key he chose was 10. Now for each letter in message he will shift it by key. i.e 

A ---> K

B ---> L

C ---> M

D ---> N

E ---> O


P ---> Z

Q ---> A


Z ---> J

So the message "this is my secret" will become "drsc sc wi combod" after the shift. Now if postman read the message he would see "drsc sc wi combod" which didn't make any sense for him and he would not find the secret. 

This is a nice solution. one of the problem with Ceaser's Cipher is that key is limited to size of alphabet set i.e 26 for English. If postman know it's a Ceaser's cipher it only take at most 26 tries to guess the correct key and reveal the secret.

So it needed improvement. One way to improve this is , instead of using a number as a key, just map each letter randomly to other letter and use
that sequence as key. What i mean is ....

QWERTYUIOPASDFGHJKLZXCVBNM and this sequence become the key.

So each A in plain message will become Q , B --> W and so on. So the message "this is my secret" will become "ziol ol dn ltektz". As there are 26 alphabet so mapping can be done in 26! ways so postman has to try 403291461126605635584000000 this much combination. This is quite good improvement over basic Ceaser Shift and it is known as substitution cipher. However there is a way to decode message encypted by substitution in reasonable time. This technique of cracking substitution cipher is known as frequency analysis.

As in mono-alphabetic substitution cipher , one letter is mapped to only one other letter. Now what postman can do is , he save all encrypted
message in his notebook and when he save some hundreds of words in his
notebook then can calculate the frequency of each letter in cipher texts and arrange them in Descending order. Suppose after doing this he get


And as in English , letters with their frequency is .....

A : 8.55 K : 0.81 U : 2.68

B : 1.60 L : 4.21 V : 1.06

C : 3.16 M : 2.53 W : 1.83

D : 3.87 N : 7.17 X : 0.19

E : 12.10 O : 7.47 Y : 1.72

F : 2.18 P : 2.07 Z : 0.11

G : 2.09 Q : 0.10

H : 4.96 R : 6.33

I : 7.33 S : 6.73

J : 0.22 T : 8.94

E is the most frequent and Z is the least frequent letter in English.

It is not wrong to say that X is mapped to E and A to T in above scenario. Hence giving the correct sequence or key.

This method is so good that many code breakers use  this technique to crack substitution cipher correctly at that time.

NOTE: In crypto world there is always a war going on between code
makers and code breakers. Code makers want to create a unbreakable system and code breakers want to create a method which can break any cipher.

After this , cryptographer named Giovan Battista Bellaso created a substitution cipher which took almost 300 years to break.

I will talk about this cipher in detail in next blog of this series.

Till then ... good bye!!

Happy hacking.


Join Hacker Noon

Create your free account to unlock your custom reading experience.