Cryptography - Encryption and Decryption

What is Cryptography? Why to use it?
What is Cryptography? Why to use it? In this era, we are sharing our private data like credit card details, bank information, passwords at many places. So importance of security is highly increased to save us from hackers. Cryptography is process of encryption and decryption of such data, where encryption is scrambling or changing a message to hide it and decryption is the process of unscrambling or changing to make the message more readable.
How it works?
Let's see how does this work. Let's first look at Caesar Cipher's algorithm.
In this method the message is encrypted based on a number. Suppose the number is 5 and the message is "python". It will be encrypted as given below.
p | y | t | h | o | n | |
---|---|---|---|---|---|---|
1 | q | z | u | i | p | o |
2 | r | a | v | j | q | p |
3 | s | b | w | k | r | q |
4 | t | c | x | l | s | r |
5 | u | d | y | m | t | s |
So the encryption is like: python + 5 = udymts. And following the same way for decryption: udymts - 5 = python.
The above method seems very simple. Every human can decrypt it with few efforts. so lets extend this a bit more. Instead of encrypting it with a single digit. Let's use a stream of numbers. For example, our message is "encryption decryption in python" and the key is 1234. The decryption will occur as given below.
1 | 2 | 3 | 4 | 1 | 2 | 3 | 4 | 1 | 2 | 3 | 4 | 1 | 2 | 3 | 4 | 1 | 2 | 3 | 4 | 1 | 2 | 3 | 4 | 1 | 2 | 3 | 4 | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
e | n | c | r | y | p | t | i | o | n | d | e | c | r | y | p | t | i | o | n | i | n | p | y | t | h | o | n | ||||
1 | f | o | d | s | z | q | u | j | p | o | e | f | d | s | z | q | u | j | p | o | j | o | q | z | u | i | p | o | |||
2 | p | e | t | r | v | k | p | f | g | t | a | r | k | q | p | p | r | a | j | q | p | ||||||||||
3 | f | u | w | l | g | h | b | s | r | q | s | b | r | q | |||||||||||||||||
4 | v | m | i | t | r | c | r | ||||||||||||||||||||||||
5 | f | p | f | v | z | r | w | m | p | p | g | i | d | t | b | t | u | k | r | r | j | p | s | c | u | j | r | r |
So the decrypted message is fpfvzrwmpp gidtbtukrr jp scujrr. These kind of guess of key is very much harder than the previous one. But it is very easy for our super computers. To prevent such guesses of key, the key must be very much longer and harder (eg. using 256 bits). The harder the key, harder to achive decryption and get the real message.
Symmetric Encryption Or Private Key Cryptography
In this method the sender and receiver share the same key privately.
Asymmentric Encryption or Public Key Cryptography
In this method the sender and receiver has common sharable public key to encrypt the message. Both do have a private key to decrypt message.
In the Deffie Hellman's encryption system, each party generates a public and a private key, while they share the public key with everyone.