Symmetric Encryption

A blog about single key cryptography

Single Key Cryptography

This type of cryptography uses just a single key. So the same key is used both for encryption and decryption as well. This is why it is also called symmetric encryption, and its main problem is that the key must be exchanged at the beginning to encrypt and decrypt the plaintext.

Image

Caesar Cipher

It is a private key encryption (symmetric encryption) method. It was first used by Julius Caesar 2000 years ago. It's a type of substitution cipher : we shift every single letter in the plaintext with a fixed number of letters and the Key itself is the number of letters we use for shifting.

Image about Caesar Cipher
  1. First we need to know that for the Encryption part we will use this formula : En(x) = (x + n) mod 26
  2. We have to consider all the characters in the plaintext.
  3. E(x) is the encrypted letter of the original x letter.
  4. Then we have to shift the given letter with n (where n is the key).
  5. Now for the Decryption part we will use this formula : En(x) = (x - n) mod 26
  6. We have to consider all the characters in the plaintext same as the encryption part.
  7. D(x) is the decrypted letter (x is letter in the ciphertext).
  8. Then we have to shift the given letter with -n (where n is the key).

If you are asking yourself why are we using mod 26, then the answer is very simple, because the size of the english alphabet is 26 which means there 26 letters in the english alphabet. That way the encrypted letter is withing the range [0, SIZE_ALPHABET - 1] so this why we use mod 26.

Caesar Cipher Example With Private Key = 3 :

  • Plaintext : this is an example
  • Ciphertext : wklv lv dq hadpsoh

Vigenere Cipher

Vigenere cipher uses a given word as the private key, the numerical representations of the letters in the key define how many characters to shift the actual letter in the plaintext. And Instead of using a single value as the key (Caesar Cipher) we have as many values as the number of letters in the private key. Therefore, we have : SIZE OF THE KEYSPACE = 26size of the key

For the Encryption part we have the same formula as we used for Caesar Cipher : Ei(xi) = (xi + Ki) mod 26

Notably xi is the actual letter in the plaintext.

Moreover Ei(xi) is the encrypted letter in the ciphertext.

In Vigenere Cipher we have to use the i-th letter of the key for encrypting the i-th letter.

For the Decryption it's quite simple we just have to use this formula : Di(xi) = (xi - Ki) mod 26

Vigenere Cipher Example With Private Key = secret :

  • Plaintext : this is just an example
  • Ciphertext : llkj ml byuk eg wbcdtew

Vernam Cipher

It was first constructed by Frank Miller in 1882. In this cryptosystem we will be using as many letters in the key as the length of the plaintext.

To prevent Information Leaking we are going to use totally random numbers to shift the letters in the plaintext, therefore the key must have the same size as the plaintext plus the key must contain random numbers.

Let's start with the algorithm, we generate a truly random sequence (as many random numbers as the letters in the plaintext) which mean we must not reuse the same numbers over and over again. Finally, we shift the letters in the plaintext with the random numbers in the same manner as in Vigenere Cipher or Caesar Cipher.

Of course if we analyze the ciphertext with Kasiski-method, there will be no information leaking because every letter in the ciphertext is equally likely.

Here is an example below of an analysis using Kasiski-method :

Image about Vernam Cipher Image about Vernam Cipher

Before we give some examples here are the formulas :

  • Encryption : Ei (xi) = (xi + VERNAMi) mod 26
  • Decryption : Di (xi) = (xi - VERNAMi) mod 26
Image about Vernam Cipher Image about Vernam Cipher Image about Vernam Cipher

The main problem as far as Vernam Cipher is concerned is how to generate the random numbers. Unfortunately nowadays we still can't generate true random numbers so we generate pseudo-random numbers and the values are not independent of each other therefore pseudo-random numbers can repeat themselves and then be predicted. That is why it's not used because it's correct implementation is nearly impossible.

Data Encryption Standard

In the early 1970s it became apparent that the commercial sector also has a need for cryptography.

For example : corporate secrets must have been transmitted securely, ATMs needed encrypted messages etc.

Here comes Data Encryption Standard (DES) which is a symmetric-key algorithm it was constructed in the early 1970 at IBM (designed mostly by Horst Feistel). It's a block cipher in other words the plaintext is processed to the ciphertext in number of blocks, hybrid of substitution cipher and permutation cipher and with that we are not able to crack DES using frequency analysis.

  1. First we have to split the plaintext into 64 bits long blocks, these blocks are the input in for the 16 rounds.
  2. These so called 16 rounds (iterations) during the encryption/decryption for DES are substituions, XOR operations etc. It's also important to note that the input for every iteration is a 64 bits long block.
  3. Every round needs a different key (it is called sub keys), and these keys are generated from the original 64 bits private key.
  4. It's main advantage is that encryption and decryption operations are very similar (requiring only the reversal of the key schedule).
  • Block size : 64 bits
  • Key size : 64 bits (56 relevants bits are used in the algorithm)
  • Number of rounds : 16
  • Number of subkeys : 16 (every sub key is 48 bits long)
  • Cipher size : 64 bits

Image about DES Image about DES Image about DES Image about DES Image about DES Image about DES Image about DES Image about DES Image about DES Image about DES Image about DES

As we saw above the Data Encryption Standard has a so-called Feistel-structure and it's main advantage is that encryption is very similar to decryption, we just use the same software and hardware, in other words we just have to use the same function we have used with encryption with the subkeys in a reverse order. The subkeys can be generated with circular left shift operations, usually in the implementation we generate all the 16 sub key at the beginning.

  • Encryption : We start with the first sub key then the second and etc.
  • Decryption : We start with the last (16th) then the 15th and etc.

Advanced Encryption Standard

After a few years, with the evolution of computers, DES could be brute forced in just 8 hours, therefore it became apparent that it was no longer secure : so there was a need for another truly secure cryptosystem.

AES (original name is Rijindael) was constructed in 2001 by Vincent Rijmen and Joan Daemen. This cryptosystem is the state-of-the-art even nowadays. It's actually a private key cryptosystem with three different key lengths : 128,192 and 256. It's a block cipher like DES but it has nothing to do with Feistel structure.

  • Plaintext block : 128 bits (4 because 1 word is 32)
  • Key size : 128 bits (4 words)
  • Number of subkeys : 10 subkeys
  • Number of rounds : 10 rounds (or 12 or 14)
  • In each round we use 1 sub key + we have to use the original 128 bits long key before applying the round-function
  • Ciphertext block 128 bits : 64 bits

Image about AES Image about AES Image about AES Image about AES Image about AES Image about AES Image about AES Image about AES Image about AES Image about AES Image about AES

Claude Shannon defined these properties for a secure cipher :

  • Confusion : Each binary digit of the ciphertext should depend on several digits of the private key. Then we want to make the relationship between the input (plaintext) and output (ciphertext) as complex as possible. Finally, the ciphertext should give no clue about the plaintext, this way non-linear transformation are preferred (these operations destroy pattern in the plaintext) and makes it hard to find the key even if large number of plaintext-ciphertext pair are available. This is why we use Substitution Boxes.
  • Diffusion : If we change a single bit in the input (plaintext) then half of the digits in the output (ciphertext) should change. There are 2 states (0 and 1) so 50% means randomness also called avalanche effect. This is why we use Permutation Boxes.