Cryptography Module 2
Cryptography Module 2
Introduction
Cryptography is the art and science of achieving security by encoding messages to make them
non-readable. Conceptual view of cryptography in shown in below fig.
Cryptanalysis is the technique of decoding messages from a non-readable format back to readable
format without knowing how they were initially converted from readable format to non-readable
format.
In other words, it is like breaking a code. This concept is shown in Fig.
Clear text or plain text signifies a message that can be understood by the sender, the recipient and
also by anyone else who gets an access to that message.
When a plain text message is codified using any suitable scheme or program, the resulting message
is called as cipher text. Using cypher text we want to hide clear text or plain text from those who
are not sender or receiver.
There are two primary ways in which a plain text message can be codified to obtain the
corresponding cipher text: Substitution and Transposition.
Substitution Techniques
In the substitution cipher technique, the characters of a plain text message are replaced by other
characters, numbers or symbols.
Caesar Cipher
It was first proposed by Julius Caesar and is termed as Caesar Cipher. Caesar Cipher is a special
case of substitution techniques wherein each alphabet in a message is replaced by an alphabet three
places down the line. For instance, using the Caesar Cipher, the plain text ATUL will become
cipher text DWXO.
Clearly, the Caesar Cipher is a very weak scheme of hiding plain text messages. All that is required
to break the Caesar Cipher is to do the reverse of the Caesar Cipher process – i.e. replace each
alphabet in a cipher text message produced by Caesar Cipher with the alphabet that is three places
up the line.
Thus, given a cipher text message L ORYH BRX, it is easy to work backwards and obtain the plain
text I LOVE YOU as shown in Fig.
In modified version of Caesar cipher original plain text alphabets may not necessarily be three
places down the line, but instead, can be any places down the line. Thus, we are now saying that
an alphabet A in plain text would not necessarily be replaced by D. So, A can be replaced by any
other alphabet in the English alphabet set, (i.e. B through Z). Thus, for each alphabet, we have 25
possibilities of replacement.
An attack on a cipher text message, wherein the attacker attempts to use all possible permutations
and combinations, is called as a Bruteforce attack. The process of trying to break any cipher text
message to obtain the original plain text message itself is called as Cryptanalysis and the person
attempting a cryptanalysis is called as a cryptanalyst.
Mono-alphabetic Cipher
The major weakness of the Caesar Cipher is its predictability. Once we decide to replace an
alphabet in a plain text message with an alphabet that is k positions up or down the order, we
replace all other alphabets in the plain text message with the same technique. Thus, the cryptanalyst
has to try out a maximum of 25 possible attacks and she is assured of success.
In Mono-alphabetic Cipher use random substitution rather than using a uniform substitution
scheme. Thus A can be replace by E and B can be replace by X and so on using random
substitution.
Now, we can now have any permutation or combination of the 26 alphabets, which means (26 x
25 x 24 x 23 x … 2) or 4 x 1026 possibilities! This is extremely hard to crack. It might actually
take years to try out these many combinations even with the most modern computers.
It’s like mono-alphabetic cypher. However, the difference between the two techniques is that
whereas the replacement alphabet set in case of the simple substitution techniques is fixed (e.g.
replace A with D, B with E, etc.), in the case of Homophonic Substitution Cipher, one plain text
alphabet can map to more than one cipher text alphabet. For instance, A can be replaced by D, H,
P, R; B can be replaced by E, I, Q, S, etc.
In Polygram Substitution Cipher technique, rather than replacing one plain text alphabet with
one cipher text alphabet at a time, a block of alphabets is replaced with another block. It does not
work on a character-by-character basis. For instance, HELLO could be replaced by YUQQW, but
HELL could be replaced by a totally different cipher text block TEUI.
Leon Battista invented the Polyalphabetic Substitution Cipher in 1568. This cipher has been
broken many times and yet it has been used extensively. The Vigenére Cipher and the Beaufort
Cipher are examples of Polyalphabetic Substitution Cipher.
This cipher uses multiple one-character keys. Each of the keys encrypts one plain text character.
The first key encrypts the first plain text character; the second key encrypts the second plain text
character and so on. After all the keys are used, they are recycled. Thus, if we have 30 one-letter
keys, every 30th character in the plain text would be replaced with the same key. This number (in
this case, 30) is called as the period of the cipher.
Playfair Cipher
The Playfair Cipher, also called as Playfair Square, is a cryptographic technique that is used for
manual encryption of data. The Playfair encryption scheme uses two main processes, as shown in
Fig.
Step 1: Creation and Population of Matrix The Playfair Cipher makes use of a 5 x 5 matrix
(table), which is used to store a keyword or phrase that becomes the key for encryption and
decryption. The way this is entered into the 5 x 5 matrix is based on some simple rules, as shown
in Fig.
For example, suppose that our keyword is PLAYFAIR EXAMPLE. Then, the 5 x 5 matrix
containing our keyword will look as shown in Fig.
Step 2: Encryption Process The encryption process consists of five steps, as outlined in Fig.
Decryption process works in the opposite direction. We also need to remove the extra X alphabets
that we had added in step #1 above, if any.
3. Our next text block to be encrypted is NA. Again, step #5 will apply as depicted in Fig.
5. We will now take a look at the fourth block of plain text, which is IS. So according to step
#5 cipher text block would be MK.
6. We will now take a look at the fifth block of plain text, which is AT. We can apply step#5
to obtain cipher text as PV.
7. We will now take a look at the sixth and last block of plain text, which is UL. We can see
that the two alphabets U and L are in the same column. Therefore, we need to apply the
logic of step #4 to get the alphabets LR.
Hill Cipher
Hill Cipher is works on multiple letters at the same time. Hence, it is a type of Polygraphic
Substitution Cipher. Hill cipher has its roots in matrix theory of Mathematics. More specifically,
we need to know how to compute the inverse of a matrix. The way the Hill Cipher works is as
shown in below.
Transposition techniques differ from substitution techniques in the way that they do not simply
replace one alphabet with another: they also perform some permutation over the plain text
alphabets.
The Rail Fence Technique is an example of transposition. It uses a simple algorithm as shown in below.
It should be quite clear that the Rail Fence Technique is quite simple for a cryptanalyst to break into.
Basic Technique Variations of the basic transposition technique such as Rail Fence Technique
exist. Such a scheme is shown in below Fig., which we shall call as Simple Columnar
Transposition Technique.
Let us examine the Simple Columnar Transposition Technique with an example. Consider the
same plain text message Come home tomorrow. Let us understand how it can be transformed into
cipher text using this technique. This is illustrated in below Fig.
The Simple Columnar Transposition Technique simply arranges the plain text as a sequence of
rows of a rectangle that are read in columns randomly. Like the Rail Fence Technique, the Simple
Columnar Transposition Technique is also quite simple to break into.
To improve the basic Simple Columnar Transposition Technique, we can introduce more
complexity. The idea is to use the same basic procedure as used by the Simple Columnar
Transposition Technique, but do it more than once. That adds considerably more complexity for
the cryptanalyst.
Cipher text produced by the Simple Columnar Transposition Technique with multiple rounds is
much more complex to crack as compared to the basic technique.
Example:
The Vernam Cipher, also called as One-Time Pad, is implemented using a random set of non-
repeating characters as the input cipher text. The most significant point here is that once an input
cipher text for transposition is used, it is never used again for any other message (hence the name
one-time). The length of the input cipher text is equal to the length of the original plain text. The
algorithm used in Vernam Cipher is described in Fig.
Let us apply the Vernam Cipher algorithm to a plain text message HOW ARE YOU using a one-
time pad NCBTZQARX to produce a cipher text message UQXTQUYFR as shown in Fig.
Vernam Cipher uses a one-time pad, which is discarded after a single use and therefore, is suitable
only for short messages.
The idea used in Book Cipher, also called as Running Key Cipher is quite simple and is similar
in principle to the Vernam Cipher. For producing cipher text, some portion of text from a book is
used, which serves the purpose of a one-time pad. Thus, the characters from a book are used as
one-time pad and they are added to the input plain text message similar to the way a one-time pad
works.
The process of encoding plain text messages into cipher text messages is called as encryption.
The reverse process of transforming cipher text messages back to plain text messages is called as
decryption.
Every encryption and decryption process has two aspects: the algorithm and the key used for
encryption and decryption.
To encrypt a plain text message, the sender (we shall henceforth treat the term sender to mean the
sender’s computer) performs encryption, i.e. applies the encryption algorithm. To decrypt a
received encrypted message, the recipient performs decryption, i.e. applies the decryption
algorithm.
Clearly, the decryption algorithm must be the same as the encryption algorithm. Otherwise,
decryption would not be able to retrieve the original message.
The second aspect of performing encryption and encryption of messages is the key. A key is
something similar to the one time pad used in the Vernam Cipher. Anyone can use the Vernam
Cipher.
In general, the algorithm used for encryption and decryption processes is usually known to
everybody. However, it is the key used for encryption and decryption that makes the process of
cryptography secure.
Broadly, there are two cryptographic mechanisms, depending on what keys are used. If the same
key is used for encryption and decryption, we call the mechanism as Symmetric Key
Cryptography. However, if two different keys are used in a cryptographic mechanism, wherein
one key is used for encryption and another, different key is used for decryption; we call the
mechanism as Asymmetric Key Cryptography.
Diffie–Hellman key exchange algorithm can be used only for key agreement, but not for
encryption or decryption of messages. Once both the parties agree on the key to be used, they need
to use other symmetric key encryption algorithms for actual encryption or decryption of messages.
Description of the Algorithm Let us assume that Alice and Bob want to agree upon a key to be
used for encrypting/decrypting messages that would be exchanged between them. Then, the Diffie-
Hellman key exchange algorithm works as shown in Fig.
Example of the Algorithm
Problems with the Algorithm
Diffie–Hellman key exchange algorithm can fall pray to the man-in-the-middle attack (or to be
politically correct, woman-in-the-middle attack), also called as bucket brigade attack.
1. Alice wants to communicate with Bob securely and therefore, she first wants to do a Diffie-
Hellman key exchange with him. For this purpose, she sends the values of n and g to Bob,
as usual. Let n = 11 and g = 7. (As usual, these values will form the basis of Alice’s A and
Bob’s B, which will be used to calculate the symmetric key K1 = K2 = K.)
2. Alice does not realize that the attacker Tom is listening quietly to the conversation between
her and Bob. Tom simply picks up the values of n and g and also forwards them to Bob as
they originally were (i.e. n = 11 and g = 7).
3. Now, let us assume that Alice, Tom and Bob select random numbers x and y.
4. Now all the three persons calculate the values of A and B as shown below.
6. Based on these values, all the three persons now calculate their keys as below. We will notice that
Alice calculates only K1, Bob calculates only K2, whereas Tom calculates both K1 and K2.
Asymmetric Key Operation
Asymmetric cryptography, also known as public-key cryptography, is a process that uses a pair of
related keys -- one public key and one private key -- to encrypt and decrypt a message and protect
it from unauthorized access or use. A public key is a cryptographic key that can be used by any
person to encrypt a message so that it can only be deciphered by the intended recipient with their
private key. A private key -- also known as a secret key -- is shared only with key's initiator.
No of Key: If there are N nodes to communicate each other. Every node have one private key and
one public key that is shared among all other (N-1) nodes. So total 2N number of keys required.
RSA Algorithm
RSA algorithm is used to generate public and private keys. RSA algorithm is shown below.
Example
1. Select 2 prime numbers -> p=17 and q=11
2. Calculate n = p×q =17 ×11=187
3. Calculate ϕ = 16 × 10= 160
4. Select ‘e’ such that e is relatively prime to ϕ =160.
5. Let e=7 that is relative prime to ϕ means gcd(e,ϕ)=1.
6. Determine d such that
de =1 mod ϕ
d × 7 = 1 mod 160
So d=23
7. Then the resulting keys are public key :
PU = {7, 187 }
PR = {23, 187 }
8. Let M=88 for encryption
9. C=887mod(187)=11
10. For Decryption:
M=Cdmod187=88