Thursday, January 23, 2020

RSA cryptosystem

RSA is an asymmetric system , which means that a key pair will be generated (we will see how soon) , a public key and a private key , obviously you keep your private key secure and pass around the public one.
The algorithm was published in the 70’s by Ron Rivest, Adi Shamir, and Leonard Adleman, hence RSA , and it sort of implement’s a trapdoor function such as Diffie’s one.
RSA is rather slow so it’s hardly used to encrypt data , more frequently it is used to encrypt and pass around symmetric keys which can actually deal with encryption at a faster speed.
We’ve got a message (“HELLO”) , and we’ve picked two tuples with two numbers each ( I will explain how these came about later). Obviously there’s no arithmetic operation we can perform with strings , so the message has to be convert it to something , so let’s say “HELLO” converts using some conversion algo to “2
Normally , in production , a lot of different techniques are used to encode the message and padding is also used
The interesting bit is how we come about those numbers , and how (5,14) is related to (11,14), and this is the interesting part i believe , let’s start:
The details of the Decryption/Encryption pair:
  1. Pick two prime numbers , I will pick 2 and 7 , lets call them p and q
P = 2 and Q = 7
2. Multiply P and Q , and that becomes the modulus
N = P * Q = 14
3. Make a list between 1 and 14 and remove the common factors:

Wednesday, January 22, 2020

Public Key Cryptography

Unlike symmetric key cryptography, we do not find historical use of public-key cryptography. It is a relatively new concept.
Symmetric cryptography was well suited for organizations such as governments, military, and big financial corporations were involved in the classified communication.
With the spread of more unsecure computer networks in last few decades, a genuine need was felt to use cryptography at larger scale. The symmetric key was found to be non-practical due to challenges it faced for key management. This gave rise to the public key cryptosystems.
The process of encryption and decryption is depicted in the following illustration −
Public Key Cryptography

Monday, January 20, 2020

Playfair Cipher

In this scheme, pairs of letters are encrypted, instead of single letters as in the case of simple substitution cipher.
In playfair cipher, initially a key table is created. The key table is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext. Each of the 25 alphabets must be unique and one letter of the alphabet (usually J) is omitted from the table as we need only 25 alphabets instead of 26. If the plaintext contains J, then it is replaced by I.
The sender and the receiver deicide on a particular key, say ‘tutorials’. In a key table, the first characters (going left to right) in the table is the phrase, excluding the duplicate letters. The rest of the table will be filled with the remaining letters of the alphabet, in natural order. The key table works out to be −
Key Table

Process of Playfair Cipher

  • First, a plaintext message is split into pairs of two letters (digraphs). If there is an odd number of letters, a Z is added to the last letter. Let us say we want to encrypt the message “hide money”. It will be written as −
    HI DE MO NE YZ
  • The rules of encryption are −
    • If both the letters are in the same column, take the letter below each one (going back to the top if at the bottom)
  • TUORI‘H’ and ‘I’ are in same column, hence take letter below them to replace. HI → QC
    ALSBC
    DEFGH
    KMNPQ
    VWXYZ
  • If both letters are in the same row, take the letter to the right of each one (going back to the left if at the farthest right)
  • TUORI‘D’ and ‘E’ are in same row, hence take letter to the right of them to replace. DE → EF
    ALSBC
    DEFGH
    KMNPQ
    VWXYZ
  • If neither of the preceding two rules are true, form a rectangle with the two letters and take the letters on the horizontal opposite corner of the rectangle.
Playfair Cipher
Using these rules, the result of the encryption of ‘hide money’ with the key of ‘tutorials’ would be −
QC EF NU MF ZV
Decrypting the Playfair cipher is as simple as doing the same process in reverse. Receiver has the same key and can create the same key table, and then decrypt any messages made using that key.