Cryptography and Cryptographic Algorithms Upto DES
Cryptography and Cryptographic Algorithms Upto DES
Algorithms
Cryptography
• The word cryptography comes from two Greek words
meaning “secret writing” and is the art and science of
information hiding.
• Application in many fields like computer security, electronic
commerce, telecommunication, etc.
• In the ancient days, cryptography was mostly referred to as
encryption – the mechanism to convert the readable
plaintext into unreadable (incomprehensible) text i.e.
ciphertext, and decryption – the opposite process of
encryption i.e. conversion of ciphertext back to the
plaintext.
• The combined study of cryptography and cryptanalysis is
known as cryptology.
Cryptosystem
• Cryptosystem is a 5-tuple/quintuple (E, D, M, K,
C), where M set of plaintexts, K set of keys, C set
of ciphertexts, E set of encryption functions e: M
K C and D set of decryption functions d: C
K M.
M = {sequences of letters}
K = {i | i is an integer and 0 ≤ i ≤ 25}
E = {Ek | k K and for all letters m, Ek(m) = (m + k) mod 26 }
D = {Dk | k K and for all letters c, Dk(c) = (26 + c – k) mod 26}
C=M
• Example: Caesar Cipher
Encryption and Decryption
• Encryption is the process of encoding a message
so that its meaning is not obvious i.e. converting
information from one form to some other
unreadable form using some algorithm called
cipher with the help of secret message called key.
• The converting text is called is plaintext and the
converted text is called ciphertext.
• Decryption is the reverse process, transforming
an encrypted message back into its normal,
original form. In decryption process also the use
of key is important.
Encryption and Decryption
• Alternatively, the terms encode and decode or
encipher and decipher are used instead of encrypt
and decrypt. That is, we say that we encode, encrypt,
or encipher the original message to hide its meaning.
Then, we decode, decrypt, or decipher it to reveal
the original message.
Key (Cryptovariable)
• A key is a parameter or a piece of information used to
determine the output of cryptographic algorithm.
• While doing the encryption, key determines the
transformation of plaintext to the cipher text and vice
versa.
• Keys are also used in other cryptographic processes like
message authentication codes and digital signatures.
• We need to select the key in a way such that attacker
should take long enough to try all possibilities i.e.
computationally infeasible.
Cipher
• A cipher is an algorithm for performing
encryption and decryption.
• The operation of cipher depends upon the
special information called key.
• Without knowledge of the key, it should be
difficult, if not nearly impossible, to decrypt
the resulting cipher into readable plaintext.
Types of Ciphers
• Historical Ciphers
• Modern Ciphers
Historical Ciphers
• Also called classical ciphers used processes like
substitution and transposition or combination of
both called product ciphers.
• These historic ciphers use the single key for both
encryption and decryption (symmetric cipher).
• To reduce the cipher attacks, in substitution
instead of monoalphabetic - a letter for letter,
polyalphabetic- one or more letters for single
letter substitution can be used.
Historical Ciphers
1
5
Modular Arithmetic
• Several important cryptosystems make use of
modular arithmetic. This is when the answer
to a calculation is always in the range 0 – n
where n is the modulus.
• To calculate the value of b mod n, you take
away as many multiples of n as possible until
you are left with an answer between 0 and n.
Clock Method for Modular Arithmetic
• Label 0 to (n-1) for mod n on a
clock.
• For addition count clockwise
the value of 2nd number from
the value of 1st number.
• For subtraction count anti-
clockwise the value of 2nd
number from the value of 1st
number.
• e.g. from figure we can see:
(2+4) mod 12=6
(2-4) mod 12=10
1
7
Reminder for Modular Arithmetic
• If “b”is positive integer and its modulo n can
be calculated as Reminder while dividing it by
n. i.e. b mod n=r, where r is reminder while
dividing “b” by “n”.
• e.g.
14 mod 12= 2 since 14/12 we get reminder 2.
29 mod 26= 3 since 29/26 we get reminder 2.
1
8
If b is a negative number then you add as
many multiples of m as necessary to get an
answer in the range 0 – n.
Examples
17 mod 5 = 2 7 mod 11 = 7
20 mod 3 = 2 11 mod 11 = 0
-3 mod 11 = 8 -1 mod 11 = 10
25 mod 5 = 0 -11 mod 11 = 0
Caesar Cipher
• It is developed by Julius Caesar.
• It is applicable only for English alphabets.
• It is a mono-alphabetic cipher wherein each letter of the plaintext is
substituted by another letter to form the ciphertext. It is a simplest form
of substitution cipher scheme.
• This cryptosystem is generally referred to as the Shift Cipher. The concept
is to replace each alphabet by another alphabet which is ‘shifted’ by some
fixed number between 0 and 25.
• For this type of scheme, both sender and receiver agree on a ‘secret shift
number’ for shifting the alphabet. This number which is between 0 and 25
becomes the key of encryption.
• The name ‘Caesar Cipher’ is occasionally used to describe the Shift Cipher
when the ‘shift of three’ is used.
• If m=plaintext, k=key and c=ciphertext, then
– Encryption: c=Ek(m)= (m+k) mod 26; 0≤m≤25
– Decryption: m=Dk(c)= (c-k) mod 26; 0≤c≤25
2
0
Modular Arithmetic and Caesar
Ciphers
• Since there are 26 letters in the English alphabet, let’s relate the letters a-z by numbers
0-25 as shown by the diagram below.
• Notice going from “A” to “D” was a shift of 3 letters over. Thus we can encrypt the word
“ZEAL” by relating “Z” with 25 on the wheel, adding 3 to get 2, and then we turn this
back into a letter, which gives us “C”. Similarly “E” → 4 → 7 → H… So we can get
ciphertext “CHDO”.
2
1
Caesar Cipher Cont…
• e.g. Plaintext=ANT, Key=3 then Ciphertext=?
Now, m1=A, m2=N and m3=T
k=3
We have, c=Ek(m)= (m+k) mod 26; 0≤m≤25
c1=(m1+k) mod 26=(0+3) mod 26=3=D
c2= =(m2+k) mod 26=(13+3) mod 26=16=Q
c3=(m3+k) mod 26=(19+3) mod 26=22=W
Hence, ciphertext=“DQW”
2
2
Polyalphabetic Ciphers
2
5
Playfair Cipher Cont…
• If two plaintext letters in a pair that fall in same row of matrix, each letter is
replaced by the letter to the right, with the first element of the row circularly
following the last. e.g. “ar” is encrypted as “rm”.
• If two plaintext letters in a pair that fall in same column of matrix, each letter is
replaced by the letter beneath, with the top element of the column circularly
following the last. e.g. “mu” is encrypted as “cm”.
• Otherwise each plaintext letter in a pair is replaced by the letter that lies in its own
row and the column occupied by the other plaintext letter. e.g. “hs” become “bp”
and “ea” become “im” or “jm”.
• e.g. plaintext= “balloon”
We can write plaintext in letter pair as ba lx lo on
From given matrix with key, letters pairs are replaced as:
ba=ib
lx=su
lo=pm
on=na
Hence, ciphertext=“ibsupmna”
Note: The plaintext is split into pairs of two letters (digraphs). If there is an odd
number of letters, a Z is added to the last letter.
For example:
PlainText: "instruments" 2
After Split: 'in' 'st' 'ru' 'me' 'nt' 'sz' 6
Vigenere Cipher
• The Vigenere cipher is the kind of polyalphabetic cipher.
• It was design by Blaise de Vigenere, a 16th century French
mathematician.
• It was used in the American civil war and was once believed to
be unbreakable.
• A Vigenere cipher uses a different strategy to create the key
stream.
• The key stream is a repetition of an initial secret key stream of
length m, where we have 1<=m<=26.
• The Vigenere cipher is a method of encrypting alphabetic text by
using a series of different Caesar ciphers based on the letters of a
keyword.
• The Vigenere cipher uses multiple mixed alphabets, each is a shift
cipher.
Vigenere Cipher
• Plain text: Cipher text:
•
• Key stream:
•
• Encryption: mod 26
• Decryption: mod 26
Example
• We can encrypt the message “She is listening” using
the 6-character keyword “PASCAL“. The initial key
stream is (15,0,18,2,0,11). The key stream is the repetition
of this initial key stream (as many times as needed) .
• Use encryption algo:
• mod 26
•
Vigenere Table
• Another way to look at Vigenere ciphers is through what is called
a Vigenere Tableau, Vigenere Table or Vigenere Square.
• The first row of this table has the 26 English letters. Shows the
plain text character to be encrypted.
• Starting with the second row, each row has the letters shifted to
the left one position in a cyclic way. For example, when B is
shifted to the first position on the second row, the letter A moves
to the end.
• The first column contains the characters to be used by the key.
Plain test
K
e
y
Example:-
• Encrypt the following plain text using vigenere cipher with
given key.
• key VIG
• plain THEBOYHASTHEBALL
• cipher OPKWWECIYOPKWIRG
Rail Fence Ciphers
• The rail fence cipher (also called a zigzag cipher) is a form of
transposition cipher.
• In the rail fence cipher, the plain-text is written downwards and
diagonally on successive rails of an imaginary fence.
• When we reach the bottom rail, we traverse upwards moving
diagonally, after reaching the top rail, the direction is changed
again. Thus the alphabets of the message are written in a zig-zag
manner.
• After each alphabet has been written, the individual rows are
combined to obtain the cipher-text.
For example,
.
Round function: Again, greater complexity generally
means greater resistance to cryptanalysis.
Fast Software encryption/Decryption: the speed of
execution of the algorithm is important.
Ease of Analysis: to be able to develop a higher level
of assurance as to its strength
Decryption: use the same algorithm with reversed
keys.
Feistel Encryption and Decryption
Data Encryption Standard (DES)
• DES is the block cipher - an algorithm that takes a
fixed-length string of plaintext bits and transforms it
through a series of complicated operations into
another ciphertext bit string of the same length.
• Product Cipher (It uses both transposition and
substitution)
• The key consists of 64 bits; however, only 56 of these
are actually used by the algorithm.
• Eight bits are used solely for checking parity, and are
thereafter discarded.
• Hence the effective key length is 56 bits, and it is
usually quoted as such.
DES
DES Round Function
• The heart of this cipher is the DES
function, f. The DES function
applies a 48-bit key to the rightmost
32 bits to produce a 32-bit output.
• Expansion Permutation Box − Since
right input is 32-bit and round key is
a 48-bit, we first need to expand
right input to 48 bits. Permutation
logic is graphically depicted in the
following illustration.
5
1
• The graphically depicted permutation logic is generally described as table in DES
specification illustrated as shown:
• XOR (Whitener). − After the expansion permutation, DES does XOR operation on
the expanded right section and the round key. The round key is used only in this
operation.
5
2
• Substitution Boxes. − The S-boxes carry out the real mixing
(confusion). DES uses 8 S-boxes, each with a 6-bit input and a 4-bit
output. Refer the following illustration
5
3
• The output of all eight s-boxes is then combined in to 32 bit section.
• Straight Permutation − The 32 bit output of S-boxes is then subjected to
the straight permutation with rule shown in the following illustration:
5
4
Key Generation
• The round-key generator
creates sixteen 48-bit
keys out of a 56-bit cipher
key.
• The process of key
generation is depicted in
the following illustration
5
5
DES
DES Analysis
• The DES satisfies both the desired properties of block
cipher. These two properties make cipher very strong.
– Avalanche effect − A small change in plaintext results in
the very great change in the ciphertext.
– Completeness − Each bit of ciphertext depends on many
bits of plaintext.
• During the last few years, cryptanalysis have found
some weaknesses in DES when key selected are weak
keys. These keys shall be avoided.
• DES has proved to be a very well designed block cipher.
There have been no significant cryptanalytic attacks on
DES other than exhaustive key search.
5
7
Public Key Cryptography Protocol
Public Key Cryptography Protocol
• Alice and Bob agree on a public-key
cryptosystem.
• Bob sends Alice his public key.
• Alice encrypts her message with Bob's public
key and sends the ciphertext.
• Bob decrypts ciphertext using his private key.
Symmetric v/s Asymmetric
Cryptography
Secret Key (Symmetric) Public Key (Asymmetric)
Number of 1 2
keys
Protection of Must be kept secret One key must be kept secret; the other
key can be freely exposed