CNS Unit-1.2 Notes
CNS Unit-1.2 Notes
CNS Unit-1.2 Notes
Cryptography Basics
Introduction: -
Cryptography is the art of achieving security by encoding messages to make them non-readable.
The Conceptual view of Cryptography is shown below:
we also use plain text during electronic conversations. For instance, when we send an email to
someone, we compose the email message using English.
1
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
.
Clear text, or plain text, signifies a message that can be understood by the sender, the
recipient, and also by anyone else who gets access to that message.
Cipher text is unreadable text message obtained after transforming plain text by applying
Encryption process.
Classical Encryption Techniques: There are two primary ways in which a plain-text
message can be codified to obtain the corresponding cipher text: substitution Cipher Techniques
and transposition Cipher Techniques.
Note that when the two approaches are used together, we call the technique product cipher.
Example:-
Resulting cipher text by using the alphabet-replacing scheme is shown below:
Thus, using the scheme of replacing each alphabet with the one that is three places down the line, a
message “I love you” shall become “L ORYH BRX” as shown below:
2
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Step2:
In Encryption process, for each plaintext letter p, substitute the ciphertext letter c with the
following calculation:
c = E(3,p) = (p+3) mod 26
A shift may be of any amount, so that the general Caesar algorithm is
c = E(k,p) = (p + k) mod 26
where k takes on a value in the range 1 to 25.
The decryption process is simply
p = D(k,c) = (c- k) mod 26
Example: -
Question: Convert the plain text ‘i Love You” to Cipher Text using Caesar Cipher method
Solution:
Therefore, message “I love you” shall become “L ORYH BRX” after encryption.
3
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
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 he/she is assured of success.
2) Mono-alphabetic Cipher: -
In this method, we use random substitution for all the alphabets in a given plain-text message, we
decide to.
This means that in a given plain-text message, each A can be replaced by any other alphabet (B
through Z), each B can also be replaced by any other random alphabet (A or C through Z), and so
on.
Here, there is no relation between the replacement of B and replacement of A. That is, if we have
decided to replace each A with D, we need not necessarily replace each B with E—we can replace
each B with any other character!
Mono-alphabetic ciphers pose a difficult problem for a cryptanalyst because it can be very difficult
to crack.
Example:
Here, the replacement of plain text happens block by block, rather than character by character.
Polygram substitution cipher technique replaces one block of plain text with another block of
cipher text.
Example:
Question:
Convert the plain text “we are discovered save yourself” into cipher text using Polyalphabetic
substitution Cipher, use the key as “deceptive”
Solution:
Consider the key and plaintext given and prepare as follows:
key: deceptivedeceptivedeceptive
plaintext: wearediscoveredsaveyourself
6
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
7
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
6) Playfair Cipher:-
The Playfair cipher, also called Playfair square, is a cryptographic technique used for manual
encryption of data.
The Playfair cipher was used by the British army in World War I and by the Australians in World
War II. This was possible because the Playfair cipher is quite fast to use and does not demand any
special equipment to be used.
It was used to protect important but not very critical information.
The Playfair encryption scheme uses two main processes, as shown below:
Example:
Constructing 5 x 5 matrix using the Keyword “Monarchy”
8
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Solution:
10
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
7) Hill Cipher:-
The Hill cipher works on multiple letters at the same time. Hence, it is a type of polygraphic
substitution cipher. The Hill cipher has its roots in the matrix theory of mathematics.
The way the Hill cipher works is as shown below:
12
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
13
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Example:
14
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
15
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
1) Rail-Fence Technique
The rail-fence technique is an example of transposition. It uses a simple algorithm as shown below:
Rail-fence technique involves writing plain text as a sequence of diagonals and then reading it
row by row to produce cipher text.
Let us illustrate the rail-fence technique with a simple example. Suppose that we have a plain-text
message: Come home tomorrow. How would we transform that into a cipher-text message using
the rail-fence technique? This is shown below:
Example:
Consider the plaintext message ‘Come home tomorrow’. Let us understand how it can be
transformed into cipher text using this technique. This is illustrated below:
16
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Example:
Convert plain-text message HOW ARE YOU using a one-time pad NCBTZQARX
17
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
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 onetime pad, and they are added to the
input plain-text message similar to the way a one-time pad works.
18
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Decryption is the process of transforming cipher-text messages back to plain text messages
Encryption transforms a plain-text message into cipher text, whereas decryption transforms a
cipher text message back into plain text. Decryption is exactly the opposite of encryption.
The encrypted cipher-text message is then sent to the receiver over a network (such as the
Internet, although it can be any other network).
The receiver’s computer then takes the encrypted message, and performs the reverse of
encryption, i.e. it performs the decryption process to obtain the original plain-text message. This is
shown below:
To encrypt a plain-text message, the sender (the sender’s computer) performs encryption by
applying the encryption algorithm.
To decrypt a received encrypted message, the recipient performs decryption by applying the
decryption algorithm.
20
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
In this scenario, the key used for Encryption is called Public Key, and the Key used for Decryption
is called as Private Key or Secrete Key.
That means, Asymmetric encryption uses a pair of Keys (k1 and k2) one for Encryption and the
other for Decryption.
21
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
This is called as brute-force attack, which works on the principle of trying every possible key in the
key range, until you get the right key.
To find the key, he attacker can write a computer program that tries many such keys in one
second. In the best case, the attacker finds the right key in few attempts, or in the worst case, it is
the 100 billionth attempt.
22
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
As shown in diagram, when the attacker notices that the decryption has yielded unintelligent plain
text, he continues the process with the next key in the sequence. Finally, he is able to find the plain
text “To: Payroll”
How does the attacker determine if the plain text, and therefore the key, are the right ones?
This can be determined depending on the value of the plain text. If the plain text seems reasonable
(i.e. very close to actual English words/sentences/numbers that make sense), it is highly probable
that the plain text is indeed what corresponds to the cipher text.
We measure key size in bits, and represent it using the binary number system. Thus, our key
might be of 40 bits, 56 bits, 128 bits, and so on.
In order to protect ourselves against a brute-force attack, the key size should be such that the
attacker cannot crack it within a specified amount of time.
Clearly, we can assume with reasonable confidence that a 128-bit key is quite safe.
23
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
We have mentioned that for this attack to succeed, the attacker should have access to sufficient
amount of cipher text.
24
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
5)Chosen-Text Attack:-
The chosen-text attack is essentially a combination of chosen plain-text attack and chosen cipher-
text attack. This is shown below:
25
P.Srinivasulu, CSE, PBRVITS. Cryptography and Network Security
Steganography
Introduction: -
Steganography is a technique that facilitates hiding of a message that is to be kept secret inside
other message or image. This results in the concealment of the secret message itself!
Steganography is the practice of concealing a message within another message or a physical
object.
In computing/electronic contexts, a computer file, message, image, or video is concealed within
another file, message, image, or video.
The advantage of steganography over cryptography alone is that the intended secret message does
not attract attention to itself as an object for inspection.
Example1:
the hidden message may be in invisible ink between the visible lines of a private letter
Example2:
Suppose that we have a secret message to send. We can take another image file and we can
replace the last two rightmost bits of each byte of that image with (the next) two bits of our secret
message.
The resulting image would not look too different, and yet carry a secret message inside! The
receiver would perform the opposite trick: it would read the last two bits of each byte of the image
file, and reconstruct the secret message.
Steganography software
Steganography software is used to perform a variety of functions in order to hide data, including
encoding the data in order to prepare it to be hidden inside another file, keeping track of which bits
of the cover text file contain hidden data, encrypting the data to be hidden and extracting hidden
data by its intended recipient.
Example:
OpenStego is an open-source steganography program;
Xiao Steganography, used to hide secret files in BMP images or WAV files
*********************************************
26