Sitemap
ZOhaib Ali

ZOhaib Ali

I am Information technology enthusiast. I work on network & data security. I am here to share my experience & knowledge with others.

Encryption Algorithms

5 min readMar 4, 2022

--

Below are few very popular encryption algorithms. Some of them might not be in much used today (like DES) as they are vulnerable to some attack. however, they are the base for understanding as how algorithms work. 3DES is still in use but now a days AES is mostly used to better security features it provides over others.

I will try to cover main points so that the information is precise and easy to read. The diagrams used in these algorithms will show the flow as how they work.

DES (Data Encryption Standard)

  • Developed by IBM, adopted as std. by US govt in 1977
  • Its implementation is based on Feistel Cipher
  • Its a Symmetric cipher i.e. same key is used to encrypt and to decrypt
  • This is a cipher that operates on 64-bit blocks of data, using 56-bit key.
  • It’s a private key system
  • Block cipher encryption (it encrypts the data in blocks of size 64-bits each)

Steps:
i. Initial Permutation (initial 64 bit key → 56 bit key → multiple 48 bit keys)
ii. 16 Feistel rounds
iii. Swapping / left right swap
iv. Final permutation | Inverse initial permutation

Press enter or click to view image in full size
Details of each rounds and functions involved
Expansion of Cipher Function

Double DES (2 DES)

DES was vulnerable to brute force attack so this was introduced.

  • Uses 2 different keys (56+56=112 bits key)

Drawback of 2 DES:

  • Meet In the Middle Attack
Press enter or click to view image in full size
  • This attack works by encrypting from one end and decrypting from other end, thus meeting in the middle to get X.

Triple DES (3DES)

  • Was designed to replace DES & 2 DES algorithms as they were weak
  • Became most widely used symmetric algo
  • It uses 2 or 3 keys with 56-bits each. The total key length adds up to 168 bits
    - When using 2 keys: K1 then K2 and again K1 is used (2x56=112 bits key length)
    - When using 3 keys: K1 → K2 → K3 is used (3x56=168 bits key length)
3 DES process by using 3 different keys

Advance Encryption Standard (AES)

  • Symmetric key block cipher
  • Stronger and faster than 3DES
  • Fixes block size = 128, 192 or 256 bits (16 bytes = 4 words | 1 word =32bit)
  • Its is based on substitution-permutation network

No. of keys required here is = n +1

  • It performs all its computations on bytes rather than bits (4x4 matrix of 16 bytes or 4 words)
  • 128 bits = 16 bytes = 4words
  • 128 bits key = 4 words i.e. [w0, w1, W2, w3] is expanded into 44 words [w0, w1, … , w43]
Press enter or click to view image in full size
Expanding AES rounds
  • Each round except the last round uses 4 transformations
  • Last round has 3 round transformation
  • There are 4 types of transformation used in each round
    - Substitution
    - Permutation
    - Mixing
    - Key-Adding

RSA (Rivest-Shamir-Adleman) algorithm

  • It is Asymmetric cryptography algo (2 diff. keys)
  • Public Key is given to everyone and Private key is kept private
  • The algorithm was invented by Rivest, Shamir and Adleman in 1978
  • Mostly used in web browsers, chat applications, email, VPNs, or for communication where 2 parties cannot meet each other physically
  • Key size from 1024–4096 bits
  • Used in PGP and GPG programs (Pretty Good Privacy, Gnu Privacy Guard) and many others.

Example of asymmetric cryptography :

  1. A client (for example browser) sends its public key to the server and requests for some data.
  2. The server encrypts the data using client’s public key and sends the encrypted data.
  3. Client receives this data and decrypts it.

Idea behind this algo:

It’s harder to factorize the larger prime numbers, and therefore private key derived from it is difficult to be compromised.

Algorithm & formulae:

Choose 2 large prime numbers ‘p’ & ‘q’

Get ZOhaib Ali’s stories in your inbox

Join Medium for free to get updates from this writer.

n=p * q
ⲫ(n)= (p-1) * (q-1)

Now, choose value of ‘e’ such that
1 < e < ⲫ(n) and gcd (ⲫ(n), e) = 1
(gcd is Greatest Common Divisor)

Then calculate
d≅ e-1 Mod ⲫ(n)
or de ≅ 1 Mod ⲫ(n)
or (de) mod ⲫ(n) = 1 Here d will such that it gives reminder as 1

Public Key, KU = {e,n}

Private Key, KR = {d,n}

Encryption :
C = Me Mod n
Where M is the number Plaintext & M < n

Decryption:
M=Cd Mod n
Where C is the number if Ciphertext

Block Diagram of RSA flow

Blowfish

  • Symmetric cipher splits message into blocks of 64-bits
  • Key Size of 32–448 bits
  • Mostly used in E-Commerce to secure payment systems
  • Known for its tremendous speed and effectiveness
  • Number of subkeys: 18 [P-array]
  • Number of rounds: 16
  • Number of substitution boxes: 4 (each having 512 entries of 32-bit each )
Encryption by Blowfish process

--

--

ZOhaib Ali
ZOhaib Ali