Lecture 2-Classical Cryptography-1
Lecture 2-Classical Cryptography-1
Classical
Cryptography
AYESHA KANWAL-SEECS
Introduction
cryptography* → the process of making and using codes to secure information.
Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI
Link: https://www.javatpoint.com/caesar-cipher-technique
Playfair Cipher
1.Generate the key Square(5×5):
1. The key square 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 the table can hold only 25
alphabets). If the plaintext contains J, then it is replaced by I.
2. The initial alphabets in the key square are the unique alphabets of the key
in the order in which they appear followed by the remaining letters of the
alphabet in order.
1. Pair cannot be made with same letter. Break the letter in single
and add a dummy letter to the previous letter.
Plain Text: “hello”
After Split: ‘he’ ‘lx’ ‘lo’
Here ‘x’ is the dummy letter.
2. If the letter is standing alone in the process of pairing, then
add an extra dummy letter with the alone letter
Plain Text: “helloe”
AfterSplit: ‘he’ ‘lx’ ‘lo’ ‘ez’
Here ‘z’ is the dummy letter.
Rules for encryption
If both the letters are in the same column: Take the letter
below each one (going back to the top if at the bottom).
If both the letters are in the same row: Take the letter to
the right of each one (going back to the leftmost if at the
rightmost position).
If neither of the above rules is true: Form a rectangle with
the two letters and take the letters on the horizontal opposite
corner of the rectangle.
Diagraph: "me"
Encrypted Text: cl
Encryption:
m -> c
e -> l
Diagraph: "st"
Encrypted Text: tl
Encryption:
s -> t
t -> l
Diagraph: "nt"
Encrypted Text: rq
Encryption:
n -> r
t -> q
Example
Suppose, the plaintext is COMMUNICATE and the key that we will use to
encipher the plaintext is COMPUTER. The key can be any word or phrase.
Let's encipher the message COMMUNICATE.
1. First, split the plaintext into digraph (by rule 2) i.e. CO MX MU NI CA TE.
2. Construct a 5*5 key-matrix (by rule 3). In our case, the key is COMPUTER.
• The first digraph is CO. The pair appears in the same row. By using Rule 4(i) CO gets
encipher into OM.
• The second digraph is MX. The pair appears in the same column. By using Rule 4(ii) MX gets
encipher into RM.
• The third digraph is MU. The pair appears in the same row. By using Rule 4(i) MU gets
encipher into PC.
• The fourth digraph is NI. The pair appears in different rows and different columns. By
using Rule 4(iii) NI gets encipher into SG.
• The fifth digraph is CA. The pair appears in different rows and different columns. By
using Rule 4(iii) CA gets encipher into PT.
• The sixth digraph is TE. The pair appears in the same row. By using Rule 4(i) TE gets
encipher into ER.
Therefore, the plaintext COMMUNICATE gets encipher (encrypted) into OMRMPCSGPTER.
How to decrypt?
Decryption of Playfair
Decrypting the Playfair cipher is as simple as doing the same process in
reverse.
Rules for Decryption:
If both the letters are in the same column: Take the letter above each
one (going back to the bottom if at the top).
If both the letters are in the same row: Take the letter to the left of each
one (going back to the rightmost if at the leftmost position).
If neither of the above rules is true: Form a rectangle with the two letters
and take the letters on the horizontal opposite corner of the rectangle.
Example
Keyword = keyword
Message = “Why, don’t you?”
Cipher text = ?
Vigenère Cipher
Vigenere Cipher is a method of encrypting alphabetic text. It uses a
simple form of polyalphabetic substitution. A polyalphabetic cipher
is any cipher based on substitution, using multiple substitution
alphabets. The encryption of the original text is done using the
Vigenère square or Vigenère table.
•The table consists of the alphabets written out 26 times in different
rows, each alphabet shifted cyclically to the left compared to the
previous alphabet, corresponding to the 26 possible Caesar Ciphers.
•At different points in the encryption process, the cipher uses a
different alphabet from one of the rows.
•The alphabet used at each point depends on a repeating keyword.
Examples
Input : Plaintext : GEEKSFORGEEKS
Keyword : AYUSH
Output : Ciphertext : GCYCZFMLYLEIM
For generating key, the given keyword is repeated in a circular manner until it
matches the length of the plain text.
The keyword "AYUSH" generates the key "AYUSHAYUSHAYU"
The plain text is then encrypted using the process explained below.
Encryption:
The first letter of the plaintext, G is paired with A, the first letter
of the key. So use row G and column A of the Vigenère square,
namely G. Similarly, for the second letter of the plaintext, the
second letter of the key is used, the letter at row E, and column
Y is C. The rest of the plaintext is enciphered in a similar fashion.
Decryption:
Decryption is performed by going to the row in the table
corresponding to the key, finding the position of the ciphertext
letter in this row, and then using the column’s label as the
plaintext. For example, in row A (from AYUSH), the ciphertext G
appears in column G, which is the first plaintext letter. Next, we
go to row Y (from AYUSH), locate the ciphertext C which is found
in column E, thus E is the second plaintext letter.
Message: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
Keyword: "CRYPTOGRAPHY“
Output : Ciphertext ?
Hill Cipher
•To encrypt a message, each block of n letters (considered as an
n-component vector) is multiplied by an invertible n × n matrix,
against modulus 26.
The matrix used for encryption is the cipher key, and it should
be chosen randomly from the set of invertible n × n matrices
(modulo 26).
Input : Plaintext: ACT
Key: GYBNQKURP
Output : Ciphertext: POH
We have to encrypt the message ‘ACT’ (n=3).The key is ‘GYBNQKURP’ which
can be written as the nxn matrix:
Encrypt the above plaintext and then decrypt to generate the same plaintext.