Cns Unit2
Cns Unit2
Cns Unit2
cipher
UNIT-2
Introduction
The decryption algorithm Dk(x) creates the plaintext from the ciphertext.
Decryption: P = Ek(C)
Secured channels:
Face-to-face exchange of the key.
They can also trust a third party to give them the same key.
They can create a temporary secret key using another kind of cipher.
If there are m people in a group who need to communicate with each other, then (m x (m
– 1))/2 keys are used.
Each person need m-1 keys to communicate with the rest of the group.
Encryption can be thought of as locking the message in a box.
Decryption can be thought of as unlocking the box.
Cryptanalysis:
Cryptography is the science and art of creating secret codes.
Cryptanalysis is the science and art of breaking those codes.
The study of cryptanalysis helps us create better secret codes.
There are four common types of cryptanalysis attacks.
We can divide traditional symmetric key ciphers into two broad categories:
Substitution Ciphers:
In a substitution cipher, we replace one symbol in the ciphertext with another
symbol.
Transposition Ciphers:
In a transposition cipher, we reorder the position of symbols in the plaintext.
Substitution ciphers:
Substitution symbol replaces one symbol with another.
If the symbol in the plaintext are alphabetic character, we can replace one character with another.
Example: A D, T Z.
If the symbol are digits ( 0 to 9), we can replace 3 with 7, and 2 with 6.
Chosen-plaintext attack:
Assume that Eve intercepts the following ciphertext.
PWUFFOGWCHFDWIWEJOUUNJORSMDWRHVCMWJUPVCCG
She tries to encrypt the short plaintext using two different algorithms, because she is not sure
which one is the affine cipher.
Algorithm 1: Plaintext: et ciphertext: WC
Algorithm 2: Plaintext: et ciphertext: WF
To find the key, Eve uses the following strategy:
Eve knows that if the first algorithm is affine, she can construct the following two equations based on
the first data set.
eW 04 22 (04 x k1 x k2 ) ≡ 22(mod 26)
tC 19 02 (19 x k1 x k2 ) ≡ 02(mod 26)
k1 =16 (16 does not have a multiplicative inverse in Z 26*)
G U I/J D A
N C E B F
H K L M O
P Q R S T
V W X Y Z
PT: Th ek ey is hi dx de nu nd er th ed ox or pa dx
CT: PO CL BX DR LG IY/JY IB/JB CG BG LX PO BI/BJ LZ LT TG IY/JY
Ciphertext : POCLBXDR LGIYIBCGBGLXPOBILZLTTGIY
Example 2: Use the Playfair cipher to encipher the message “COMSEC means
communications security” using the secret key “GALOIS”.(name of the
mathematician).
COMSEC means communications security
G A L O I/J
S B C D E
F H K M N
P Q R T U
V W X Y Z
Plaintext: co ms ec me an sc om mu ni ca ti on sx se cu ri ty
Ciphertext: DLFDSDNDIHBDDTNTUEBLUOIMCVBSERULYO
Cryptanalysis of a Playfair Cipher:
Brute-force attack on a Playfair cipher is very difficult.
A cryptanalyst can use a ciphertext-only attack based on the digram frequency test to find the
key.
Vigenere Cipher:
Vigenere cipher uses a different strategy to create the key stream .
Keystream is a repetition of an initial secret key stream of length m, where 1 ≤ m ≤ 26.
Suppose Alice and Bob agree k= (k1,k2,k3……….km).
Where,
P = P1, P2, P3, ….
C = C1, C2, C3, ….
K = [(k1,k2,k3……….km), (k1,k2,k3……….km),….]
Encryption : Ci = Pi + ki
Decryption : Pi = Ci - ki
The Vigenere cipher can be seen as combinations of m additive ciphers.
We can say that the additive cipher is a special case of vigenere cipher in which m=1
Cryptanalysis of Vigenere Ciphers :
Eve can use technique to decipher the intercepted cipher text. The cryptanalysis
consist of :
Finding the length of key
Finding the key itself.
Several methods to find the length of key Kasiski test
Kasiski Test:
The cryptanalyst searches for repeated text segments, of at least three characters, in the
ciphertext.
Suppose, that two of these segment are found and the distance between them is d.
The cryptanalyst assumes that d/m where m is the key length.
If more repeated segments can be found with distance d1, d2, d3,….. dn then, gcd(d1,d2,
d3,…..dn)/m
Example: Let us assume that the intercepted text is as follows:
GCD = 4
Key value = CODE.
JULIUSCAESARUSEDACRYPTOSYSTEMINHISWARWHICHISNOWREFERREDTOASCAES
ARCIPHERITISANADDITIVECIPHERWITHTHEKEYSETTOTHREEEACHCHARACTERINT
HEPLAINTEXTISSHIFTEDTHREECHARACTERSTOCREATETHECIPHERTEXT.
Julius Caesar used a cryptosystem in his wars, which is now referred to as Caesar cipher. It is an
additive cipher with the key set to three. Each character in the plaintext is shifted three character to
create the ciphertext.
Hill Cipher:
The Hill Cipher was invented by Lester S. Hill in 1929
It acts on groups of letters.
It is a polygraphic substitution cipher, as it can work on digraphs, trigraphs (3 letter blocks) or
theoretically any sized blocks.
Key is a square matrix of size m x m matrix in which m is the size of the block( 2 x 2 matrix for
digraphs, a 3 x 3 matrix for trigraphs).
Encryption
Turn the plaintext into digraphs (or trigraphs) and each of these into a column vector.
To encrypt a message, each block of n letters is multiplied by an m × m matrix, against modulus
26.
C = K*P mod 26
Decryption
To decrypt the message, each block is multiplied by the inverse of the matrix
Example:
Let us see an example:
We have been given the phrase “code is ready” and a 4 X 4 key matrix. We can append some
bogus characters (“z”) to the plain text making the plain text “codeisreadyz” and making it into a
3 X 4 plain text matrix.
Plain Text Matrix =
Key Matrix =
Now, performing the encryption:
C = PK
Thus,
The cipher text obtained from the ciphertext matrix is: “OHKNIHGKLISS”
Example: (Assignment)
Encrypt the plaintext message "short example" using the keyword hill with a 2 x 2 matrix.
The first step is to turn the keyword hill into a matrix.
hill 7 8 11 11
One-Time pad:
One of the goals of cryptography is perfect secrecy.
A study by Shannon has shown that perfect secrecy can be achieved if each plaintext symbol is
encrypted with a key randomly chosen from a key domain.
This idea is used in a cipher called one-time pad, invented by Vernam.
Each character is chosen randomly from the key domain (00, 01,02,……,25) – i.e., if the first
character is encrypted using the key 4, second by 02, the third by using 21 and so on.
Here, the cipher text only attack is impossible. Other type of attack are also impossible if the
sender changes the key each time.
Key has same length as the plaintext.
Rotor cipher:
It uses the idea behind monoalphabetic substitution but changes the mapping between the
plaintext and the ciphertext character for each plaintext character.
Transposition cipher does not substitute one symbol for another, instead it changes the location
of the symbols.
A transposition cipher reorders (transposes) the symbols.
Different transposition ciphers:
1. Keyless Transposition Ciphers
2. Keyed Transposition Ciphers
3. Combining Two Approaches
Keyless transposition ciphers
Simple transposition ciphers, which were used in the past, are keyless.
There are two methods for permutating character:
1.Text is written into table column by column and transmit row by row.
2.Text is written into table row by row and transmit column by column.
Example: Rail Fence cipher
Plaintext is arranged in two line as a zigzag pattern(Column by column) and the ciphertext is
created reading the pattern row by row.
Plaintext “Meet me at the park”
Ciphertext MEMATEAKETETHPR
Example:
Alice and Bob can agree on the number of columns. Alice writes the plaintext, row by row, in a table
of four columns.
Plaintext “Meet me at the park”
Ciphertext “MMTAEEHREAEKTTP”.
Bob receives the ciphertext and follows the reverse process. He writes column by column and
reads row by row.
The following shows the permutation of each character in the plaintext into the ciphertext
based on the positions.
The second character in the plaintext has moved to the fifth position in the ciphertext; the third
character has moved to the ninth position; and so on.
Although the characters are permuted, there is a pattern in the permutation: (01, 05, 09, 13),
(02, 06, 10, 13), (03, 07, 11, 15), and (08, 12).
In each section, the difference between the two adjacent numbers is 4.
Keyed transposition ciphers:
Divide the plaintext into groups of predetermined size, called blocks, and then use a key to
permute the characters in each block separately.
Example: Alice needs to send the message “Enemy attacks tonight” to Bob. Alice and Bob agrees
with block size =5.
The key used for encryption and decryption is a permutation key, which shows how the character
are permuted.
Combining Two approaches:
Cryptanalysis of transposition ciphers:
Transposition ciphers are vulnerable to several kinds of ciphertext only attacks.
Statistical Attack: A transposition cipher does not change the frequency of
letters in the ciphertext, it only reorders the letters.
Brute-force attack: Eve can try all possible keys to decrypt the message.
Pattern attack: The ciphertext created from a keyed transposition cipher has
some repeated patterns.
Stream ciphers:
In a stream cipher, encryption and decryption are done typically on one symbol at a time.
Stream ciphers - Call the plaintext stream P, the ciphertext stream C, and the key stream K.
Figure: Stream cipher
Block cipher:
In a block cipher, a group of plaintext symbols of size m (m > 1) are encrypted together creating
a group of ciphertext of the same size.
A single key is used to encrypt the whole block even if the key is made of multiple values.
Less time consuming compare to block More time consuming compare to stream
cipher. cipher.
Only one bit is encrypted at a time, hence Block of data is encrypted at a time, hence
it is faster. it is slower.
Example: One Time Pad, Additive cipher, Example: Playfair cipher, Hill cipher
Vegenere cipher.
Data Encryption Standard
Unit 2 - Chapter 2
Introduction
Figure: S-boxes
The substitution in each box follows a pre-determined rule based on a 4-rows by 16 column
table.
The combination of bits 1 and 6 of the input defines one of four rows.
The combination of bits 2 through 5 defines one of the sixteen columns.
For example: the seventh bit of the input becomes the second bit of the output.
Cipher and Reverse Cipher:
Using mixers and swappers, we can create the cipher and reverse cipher,
each having 16 rounds.
The cipher is used at the encryption site; the reverse cipher is used at the
decryption site.
The whole idea is to make the cipher and the reverse cipher algorithms
similar.
First approach:
To achieve this one approach is to make the last round(round 16) different from the others.
it has only a mixer and no swapper.
Although the rounds are not aligned, the elements (mixer or swapper) are aligned.
the mixer is a self-inverse; so is a swapper. The final and initial permutations are also
inverses of each other.
The left section of the plaintext at the encryption site, L0, is enciphered as L16 at the
encryption site; L16 at the decryption is deciphered as L0 at the decryption site.
The situation is the same with R0 and R16. A very important point we need to remember about
the ciphers is that the round keys (K1 to K16) should be applied in the reverse order.
At the encryption site, round 1 uses K1 and round 16 uses K16; at the decryption site, round 1
uses K16 and round 16 uses K1.
Pseudocode for DES cipher:
Alternate approach:
In the first approach, round 16 is different from other rounds; there is no
swapper in this round. This is needed to make the last mixer in the cipher
and the first mixer in the reverse cipher aligned.
We can make all 16 rounds the same by including one swapper to the
16th round and add an extra swapper after that (two swappers cancel the
effect of each other). We leave the design for this approach as an
exercise.
Key generation:
The round-key generator creates sixteen 48-bit keys out of a 56-bit
cipher key.
However, the cipher key is normally given as a 64-bit key in which 8
extra bits are the parity bits, which are dropped before actual key
generation process.
Figure: Key generation
Parity drop:
The preprocessor before key expansion is a compression transposition step, that is called Parity-bit
drop.
It drops the parity bits(8,16,24,32,…..64) from the 64-bit key and permutes the rest of the bits.
The remaining 56-bit value is the actual cipher key which is used to generate round keys.
During the key schedule algorithm in DES, the initial 56-bit key undergoes a series of
transformations to generate 16 48-bit subkeys, one for each round of encryption and
decryption. The parity drop is a step in this process where the least significant bit (LSB) of
each byte in the 56-bit key is dropped, resulting in a 64-bit key after the parity bits are
removed.
Shift left:
After the straight permutation, the key is divided into two 28-bits parts.
Each part is shifted left(circular shift) one or two bits.
In rounds 1,2,9 and 16, shifting is one bit; in the other rounds, it is two bits.
The two parts are then combined to form a 56-bit part.
P-boxes:
The following design criteria were implemented in the design of P-
boxes to achieve this goal.
Each S-box input comes from the output of a different S-box
No input to a given S-box comes from the output from the same box.
The four outputs from each S-box go to six different S-boxes.
No two output bits from an S-box go to the same S-box
If we number the eight S-boxes S1, S2, …… S8,
An output of Sj-2 goes to one of the first two bits of Sj.
An output bit from Sj-1 goes to one of the last two bits of Sj.
An output of Sj+1 goes to one of the two middle bits of Sj.
For each S-box, the two output bits go to the first or last two bits of an S-box. The
other two output bits go to the middle bits of an S-box.
If an output bit from Sj goes to one of the middle bits in Sk(in the next round), then an
output bit from Sk cannot go to the middle bit of Sj. If we let j = k, this implies that
none of the middle bits of an S-box can go to one of the middle bits of the same S-
box in the next round.
Number of rounds:
DES uses sixteen rounds of Feistel ciphers.
It has been proved that after eight rounds, each ciphertext is a
function of every plaintext bit and every key bit; the ciphertext is
thoroughly a random function of plaintext and ciphertext.
Therefore, it looks like 8 rounds should be enough.
However, experiments have found that DES versions with less than 16
rounds are even more vulnerable to known-plaintext than brute-force
attack, which justify the use of 16 rounds by the designers of DES.
DES Weaknesses
S-Boxes
• In S-box 4, the last three output bits can be derived in the same
way as the first output bit by complementing some of the input
bits.
• Two specifically chosen inputs to an S-box array can create the
same output.
• It is possible to obtain the same output in a single round by
changing bits in only three neighboring S-boxes.
D-boxes
• It is not clear why designers of DES used the initial and final
permutations; these have no security benefits.
• In the expansion permutation (inside the function), the first and
fourth bits of every 4-bit series are repeated.
Weakness in the Cipher key:
Brute force attack adversary will check with – 256 keys
• One computer with processor à more than thousand years
• Computer with parallel processing à 20 hours
• Computer network with parallel processing à 120 days (key
challenged by RSA Laboratories)
Solution:
Is to use triple DES (3DES) with two keys(112 bits).
Triple DES with three keys(168 keys).
Weakness in cipher key-Weak keys
Four out of 256 keys are called weak keys
Round keys created from weak keys will have the same pattern as cipher key.
Weakness in cipher key-Weak keys
What is the disadvantage of using a weak key?
Weakness in cipher key-Weak keys:
Let us try the first weak key in Table 6.18 to encrypt a block two times.
After two encryptions with the same key the original plaintext block is created. Note that we have
used the encryption algorithm two times, not one encryption followed by another decryption.
Semi-weak Keys:
There are six key pairs called semi weak keys
A Semi weak keys creates two different round keys and each of them is repeated eight times
Round key created from each pair are the same with different order
Weakness in cipher key – Possible weak keys
48 Keys are possible weak keys
A possible weak key is a key that creates four distinct round keys
16round keys = 4 groups à each group 4 equal round key
DES, as the first important block cipher, has gone through much scrutiny.
Among the attempted attacks, three are of interest
Brute Force attack
Differential cryptanalysis
Linear cryptanalysis
Brute Force attack
We have discussed the weakness of short cipher key in DES.
Combining this weakness with the key complement weakness, it is clear that DES can be broken using 255
encryptions.
However, today most applications use either 3DES with two keys (key size of 112) or 3DES with three
keys (key size of 168).
These two multiple-DES versions make DES resistant to brute-force attack.
Differential cryptanalysis
It has been revealed that the designers of DES already knew about this type of attack and designed S-boxes and
chose 16 as the number of rounds to make DES specifically resistant to this type of attack.
Linear cryptanalysis
Linear cryptanalysis is newer than differential cryptanalysis. DES is more vulnerable to linear cryptanalysis
than to differential cryptanalysis, probably because this type of attack was not known to the designers of
DES. S-boxes are not very resistant to linear cryptanalysis. It has been shown that DES can be broken
using 243 pairs of known plaintexts. However, from the practical point of view, finding so many pairs is
very unlikelly.
THANK YOU