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 −
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 −
o If both the letters are in the same column, take the letter below each one
(going back to the top if at the bottom)
T U O R I
A L S B C
‘H’ and ‘I’ are in same column, hence take letter
D E F G H
below them to replace. HI → QC
K M N P Q
V W X Y Z
● 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)
T U O R I
A L S B C
‘D’ and ‘E’ are in same row, hence take letter
D E F G H
to the right of them to replace. DE → EF
K M N P Q
V W X Y Z
● 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.
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.
Vigenere Cipher:
This scheme of cipher uses a text string (say, a word) as a key, which is then used for doing a
number of shifts on the plaintext.
For example, let’s assume the key is ‘point’. Each alphabet of the key is converted to its
respective numeric value: In this case,
p → 16, o → 15, i → 9, n → 14, and t → 20. Thus, the key is: 16 15 9 14 20.
Process of Vigenere Cipher
● The sender and the receiver decide on a key. Say ‘point’ is the key. Numeric
representation of this key is ‘16 15 9 14 20’.
● The sender wants to encrypt the message, say ‘attack from south east’. He will
arrange plaintext and numeric key as follows −
● He now shifts each plaintext alphabet by the number written below it to create
ciphertext as shown below −
● Here, each plaintext character has been shifted by a different amount – and that
amount is determined by the key. The key must be less than or equal to the size of
the message.
● For decryption, the receiver uses the same key and shifts received ciphertext in
reverse order to obtain the plaintext.
Variants of Vigenere Cipher:
There are two special cases of Vigenere cipher −
● The keyword length is same as plaintect message. This case is called Vernam
Cipher. It is more secure than typical Vigenere cipher.
● Vigenere cipher becomes a cryptosystem with perfect secrecy, which is
called One-time pad.
XOR Cipher
XOR Encryption is an encryption method used to encrypt data and is hard to crack by brute-force
method, i.e generating random encryption keys to match with the correct one.
Below is a simple implementation in C++. The concept of implementation is to first define XOR –
encryption key and then to perform XOR operation of the characters in the String with this key which
you want to encrypt. To decrypt the encrypted characters we have to perform XOR operation again
with the defined key. Here we are encrypting the entire String.
As introduction to stream ciphers, and to demonstrate that a perfect cipher does exist, we describe the
Vernam Cipher, also known as the one-time-pad.
Gilbert Vernam invented and patented his cipher in 1917 while working at AT&T. The teletype had
been recently introduced, and along with this the commerical Baudot code. Now messages were
uniformly thought of as streams of zero's and one's (But the word "bit" was not yet invented. This is
due to Shannon in the 40's.)
Vernam proposed a bit-wise exclusive or of the message stream with a truely random zero-one stream
which was shared by sender and receipient.
Example:
SENDING
-------
message: 0 0 1 0 1 1 0 1 0 1 1 1 ...
pad: 1 0 0 1 1 1 0 0 1 0 1 1 ...
XOR ---------------------------
cipher: 1 0 1 1 0 0 0 1 1 1 0 0 ...
RECEIVING
---------
cipher: 1 0 1 1 0 0 0 1 1 1 0 0 ...
pad: 1 0 0 1 1 1 0 0 1 0 1 1 ...
XOR ---------------------------
message: 0 0 1 0 1 1 0 1 0 1 1 1 ...
This cipher is unbreakable in a very strong sense. The intuition is that any message can be
transformed into any cipher (of the same length) by a pad, and all transformations are equally likely.
Given a two letter message, there is a pad which adds to the message to give OK, and another pad
which adds to the message to give NO. Since either of these pads are equally likely, the message is
equally likely to be OK or NO.