ICS Unit 2
ICS Unit 2
INTRODUCTION TO CRYPTOGRAPHY:
An original message is known as the plaintext, while the coded message is called the ciphertext.
The process of converting from plaintext to ciphertext is known as enciphering or encryption; restoring theplaintext from
the ciphertext is deciphering or decryption.
The many schemes used for encryption constitute the area of study known as cryptography. Such a scheme is known as a
cryptographic system or a cipher.
Techniques used for deciphering a message without any knowledge of the enciphering details fall into the area of
cryptanalysis.
Cryptanalysis is what the layperson calls “breaking the code.”The areas of cryptography and cryptanalysistogether are
called cryptology.
Plaintext: This is the original intelligible message or data that is fed into the algorithm as input.
Encryption algorithm: The encryption algorithm performs various substitutions and transformations on the plaintext.
Secret key: The secret key is also input to the encryption algorithm.The key is a value independent of the plaintextand of the
algorithm. The algorithm will produce a different output depending on the specific key being used at the time.The exact substitutions
and transformations performed by the algorithm depend on the key.
Ciphertext: This is the scrambled message produced as output. It depends on the plaintext and the secret key.
Decryption algorithm: This is essentially the encryption algorithm run in reverse. It takes the ciphertext and the secret key and
produces the original plaintext.
Substitution Technique:
Caesar Cipher
Monoalphabetic Cipher
Playfair Cipher
Polyalphabetic Cipher
Vignere Cipher
Caesar Cipher
This the simplest substitution cipher by Julius Caesar. In this substitution technique, to encrypt the plain text,
each alphabet of the plain text is replaced by the alphabet three places further it. And to decrypt the cipher text
each alphabet of cipher text is replaced by the alphabet three places before it.
Let us take a simple example:
Plain Text: meet me tomorrow
Cipher Text: phhw ph wrpruurz
Look at the example above, we have replaced, ‘m’ with ‘p’ which occur three places after, ‘m’. Similarly, ‘e’ is
replaced with ‘h’ which occurs in three places after ‘e’.
Monoalphabetic Cipher
Monoalphabetic cipher is a substitution cipher, where the cipher alphabet for each plain text alphabet is fixed,
for the entire encryption.
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 form the ciphertext.
Playfair Cipher
Playfair cipher is a substitution cipher which involves a 5X5 matrix. Let us discuss the technique of this Playfair
cipher with the help of an example:
Key: KEYWORD
Now, we have to convert this plain text to ciphertext using the given key. We will discuss the further process in
steps.
Step 1: Create a 5X5 matrix and place the key in that matrix row-wise from left to right. Then put the remaining
alphabet in the blank space.
Note: If a key has duplicate alphabets, then fill those alphabets only once in the matrix, and I & J should be kept
together in the matrix even though they occur in the given key.
Step 2: Now, you have to break the plain text into a pair of alphabets.
Pair: me et me to mo rx ro wz
Note
Pair of alphabets must not contain the same letter. In case, pair has the same letter then break it and add ‘x’ to the
previous letter. Like in our example letter ‘rr’ occurs in pair so, we have broken that pair and added ‘x’ to the
first ‘r’.
In case while making pair, the last pair has only one alphabet left then we add ‘z’ to that alphabet to form a pair
as in our above example, we have added ‘z’ to ‘w’ because ‘w’ was left alone at last.
If a pair has ‘xx’ then we break it and add ‘z’ to the first ‘x’, i.e. ‘xz’ and ‘x_’.
Step 3: In this step, we will convert plain text into ciphertext. For that, take the first pair of plain text and check
for cipher alphabets for the corresponding in the matrix. To find cipher alphabets follow the rules below.
Note
If both the alphabets of the pair occur in the same row replace them with the alphabet to their immediate right.
If an alphabet of the pair occurs at extreme right then replace it with the first element of that row, i.e. the last
element of the row in the matrix circularly follows the first element of the same row.
If the alphabets in the pair occur in the same column, then replace them with the alphabet immediate
below them. Here also, the last element of the column circularly follows the first element of the same column.
If the alphabets in the pair are neither in the same column and nor in the same row, then the alphabet is
replaced by the element in its own row and the corresponding column of the other alphabet of the pair.
Pair: me et me to mo rx ro wz
Cipher Text: kn ku kn kz ks ta kc yo
So, this is how we can convert a plain text to ciphertext using Playfair cipher. When compared with
monoalphabetic cipher Playfair cipher is much more advanced. But still, it is easy to break.
Polyalphabetic Cipher
Polyalphabetic cipher is far more secure than a monoalphabetic cipher. As monoalphabetic cipher maps a plain
text symbol or alphabet to a ciphertext symbol and uses the same ciphertext symbol wherever that plain text
occurs in the message.
But polyalphabetic cipher, each time replaces the plain text with the different ciphertext.
vigenere cipher
The vigenere cipher is an algorithm that is used to encrypting and decrypting the text. The vigenere
cipher is an algorithm of encrypting an alphabetic text that uses a series of interwoven caesar ciphers. It
is based on a keyword's letters. It is an example of a polyalphabetic substitution cipher. This algorithm
is easy to understand and implement. This algorithm was first described in 1553 by Giovan Battista
Bellaso. It uses a Vigenere table or Vigenere square for encryption and decryption of the text. The
vigenere table is also called the tabula recta.
When the vigenere table is given, the encryption and decryption are done using the vigenere table (26
To generate a new key, the given key is repeated in a circular manner, as long as the length of the plain
text does not equal to the new key.
Encryption
The first letter of the plaintext is combined with the first letter of the key. The column of plain text "J"
and row of key "B" intersects the alphabet of "K" in the vigenere table, so the first letter of ciphertext is
"K".
Similarly, the second letter of the plaintext is combined with the second letter of the key. The column of
plain text "A" and row of key "E" intersects the alphabet of "E" in the vigenere table, so the second letter
of ciphertext is "E".
This process continues continuously until the plaintext is finished.
Ciphertext = KENTUTGBOX
Method 2
When the vigenere table is not given, the encryption and decryption are done
by Vigenar algebraically formula in this method (convert the letters (A-Z) into
the numbers (0-25)).
E = (P + K ) mod
i 26
i i
26
Plaintext J A V A T P O I N
Key B E S T B E S T B
Ciphertext K E N T U T G B O
Transposition Technique in Cryptography
Transposition technique is an encryption method which is achieved by
performing permutation over the plain text. Mapping plain text into cipher text
using transposition technique is called transposition cipher.
Step 2: Then, to obtain the cipher text the text is read as a sequence of rows.
Now, we will write this plain text sequence wise in a diagonal form as you can
see below:
Looking at the image, you would get it why it got named rail fence because it
appears like the rail fence.
Once you have written the message as a sequence of diagonals, to obtain the
cipher text out of it you have to read it 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
Rail fence cipher is easy to implement and even easy for a cryptanalyst to
break this technique. So, there was a need for a more complex technique.
Step 1: The plain text is written in the rectangular matrix of the initially defined
size in a row by row pattern.
Step 2: To obtain the cipher text read the text written in a rectangular matrix
column by column. But you have to permute the order of column before
reading it column by column. The obtained message is the cipher text
message.
Now, put the plain text in the rectangle of a predefined size. For our example,
the predefined size of the rectangle would be 3×4. As you can see in the
image below the plain text is placed in the rectangle of 3×4. And we have also
permuted the order of the column.
Now, to obtain the cipher text we have to read the plain text column by
column as the sequence of permuted column order. So, the cipher text
obtained by the columnar transposition technique in this example is:
Similar to the rail fence cipher, the columnar cipher can be easily broken.
Step 1: The plain text is written in the rectangle of predetermined size row by
row.
Step 2: To obtain the cipher text, read the plain text in the rectangle, column
by column. Before reading the text in rectangle column by column, permute
the order of columns the same as in basic columnar technique.
Step 3: To obtain the final cipher text repeat the steps above multiple time.
Let us put this plain text in the rectangle of predefined size of 3×4.
Proceeding with the next step, the order of the columns of the matrix is
permuted as you can see in the image below:
Now after the first round the cipher text obtained is as follow:
Now, again we have to put the cipher text of round 1 in the rectangle of size
3×4 row by row and permute the order of columns before reading the cipher
text for round 2. In the second round, the permuted order of the column is 2,
3, 1, 4.
So, the obtained cipher text for round 2 is MOOTRTREOEMW. In this way,
we can perform as many iterations as requires. Increasing the number of
iterations increases the complexity of the techniques.
Data Encryption Standard (DES)
DES stands for Data Encryption Standard. DES is a symmetric-key block cipher created in the
early 1970s by an IBM team and adopted by the National Institute of Standards and Technology
(NIST).
The algorithm takes the plain text in 64-bit blocks and The DES algorithm uses a key of 56-bit
size. converts them into ciphertext using 48-bit keys. Using this key, the DES takes a block of
64-bit plain text as input and generates a block of 64-bit cipher text.
The DES process has several steps involved in it, where each step is called a round. Depending
upon the size of the key being used, the number of rounds varies. For example, a 128-bit key
requires 10 rounds.
To put it in simple terms, DES takes 64-bit plain text and turns it into a 64-bit ciphertext. & the
same key is used when it’s time to decrypt the text.
1. The process begins with the 64-bit plain text block getting handed over to an initial
permutation (IP) function.
3. Next, the initial permutation (IP) creates two halves of the permuted block,
4. Each LPT and RPT goes through 16 rounds of the encryption process.
5. Finally, the LPT and RPT are rejoined, and a Final Permutation (FP) is performed on the
newly combined block.
1. Key transformation
2. Expansion permutation
3. S-Box permutation
4. P-Box permutation
For decryption, we use the same algorithm, and we reverse the order of the 16 round keys.
The plain text is divided into smaller chunks of 64-bit size. The IP is performed before the first
round. This phase describes the implementation of the transposition process. For example, the
58th bit replaces the first bit, the 50th bit replaces the second bit, and so on. The resultant 64-bit
text is split into two equal halves of 32-bit each called Left Plain Text (LPT) and Right Plain
Text (RPT).
Applications of DES Algorithm
In this section, we are going to learn about some of the applications of the DES Algorithm.
3. It is used to develop a new form of DES, called Triple DES (using a 168-bit key formed using
three keys)
AES(Advanced Encryption Standard):
Advanced Encryption Standard (AES) is a specification for the encryption of
electronic data established by the U.S. National Institute of Standards and
Technology (NIST) in 2001. AES is widely used today as it is much stronger than
DES and triple DES despite being harder to implement. AES is a highly
trusted encryption algorithm used to secure data by converting it into an
unreadable format with the proper key.
AES encryption uses various key lengths (128, 192, or 256 bits) to provide strong
protection against unauthorized access. This data security measure is efficient and
widely implemented in securing internet communication, protecting sensitive
data, and encrypting files. AES, a cornerstone of modern cryptography, is
recognized globally for its ability to keep information safe from cyber threats.
That means it takes 128 bits as input and outputs 128 bits of encrypted cipher text.
o Sub Bytes
o Shift Rows
o Mix Columns
o Add Round Key
Sub-Bytes: In this step, it converts each byte of the state array into
hexadecimal, divided into two equal parts. These parts are the rows and columns,
mapped with a substitution box (S-Box) to generate new values for the final state
array.
Shift Rows: It swaps the row elements among each other. It skips the first row.
It shifts the elements in the second row, one position to the left. It also shifts the
elements from the third row two consecutive positions to the left, and it shifts the last
row three positions to the left.
Mix Columns: It multiplies a constant matrix with each column in the state
array to get a new column for the subsequent state array. Once all the columns are
multiplied with the same constant matrix, you get your state array for the next step.
This particular step is not to be done in the last round.
Add Round Key: The respective key for the round is XOR’d with the state
array is obtained in the previous step. If this is the last round, the resultant state array
becomes the ciphertext for the specific block; else, it passes as the new state array
input for the next round.
Advantages of AES
The AES algorithm provides several advantages over older algorithms such
as the Data Encryption Standard (DES):
The Public key is used for encryption, and the Private Key is used for decryption.
Decryption cannot be done using a public key. The public key is well known, but the private
key is secret and it is known only to the user who owns the key.
o Example 1:
o This example shows how we can encrypt plaintext 9 using the RSA public-key
encryption algorithm. This example uses prime numbers 7 and 11 to generate
the public and private keys.
o Explanation:
o Step 1: Select two large prime numbers, p, and q.
o p=7
o q = 11
o Step 2: Multiply these numbers to find n = p x q, where n is called the modulus
for encryption and decryption.
o First, we calculate
o n=pxq
o n = 7 x 11
o n = 77
o Step 3: Choose a number e less that n, such that n is relatively prime to (p - 1) x
(q -1). It means that e and (p - 1) x (q - 1) have no common factor except 1.
Choose "e" such that 1<e < φ (n), e is prime to φ (n), gcd (e, d (n)) =1.
o Second, we calculate
o ADVERTISEMENT
o φ (n) = (p - 1) x (q-1)
o φ (n) = (7 - 1) x (11 - 1)
o φ (n) = 6 x 10
o ADVERTISEMENT
o φ (n) = 60
o Let us now choose relative prime e of 60 as 7.
o ADVERTISEMENT
o Thus the public key is <e, n> = (7, 77)
o Step 4: A plaintext message m is encrypted using public key <e, n>. To find
ciphertext from the plain text following formula is used to get ciphertext C.
o To find ciphertext from the plain text following formula is used to get ciphertext
C.
o C = me mod n
o C = 97 mod 77
o C = 37
o Step 5: The private key is <d, n>. To determine the private key, we use the
following formula d such that:
o De mod {(p - 1) x (q - 1)} = 1
o 7d mod 60 = 1, which gives d = 43
o The private key is <d, n> = (43, 77)
o Step 6: A ciphertext message c is decrypted using private key <d, n>. To
calculate plain text m from the ciphertext c following formula is used to get plain
text m.
o m = cd mod n
o m = 3743 mod 77
o m=9
o In this example, Plain text = 9 and the ciphertext = 37
o Example 2:
In an RSA cryptosystem, a particular A uses two prime numbers, 13 and 17, to
generate the public and private keys. If the public of A is 35. Then the private key of
A is ……………?.
o Explanation:
o Step 1: in the first step, select two large prime numbers, p and q.
o p = 13
o q = 17
o Step 2: Multiply these numbers to find n = p x q, where n is called the modulus
for encryption and decryption.
o First, we calculate
o n=pxq
o n = 13 x 17
o n = 221
o Step 3: Choose a number e less that n, such that n is relatively prime to (p - 1) x
(q -1). It means that e and (p - 1) x (q - 1) have no common factor except 1.
Choose "e" such that 1<e < φ (n), e is prime to φ (n), gcd (e, d (n)) =1.
o Second, we calculate
o φ (n) = (p - 1) x (q-1)
o φ (n) = (13 - 1) x (17 - 1)
o φ (n) = 12 x 16
o φ (n) = 192
o g.c.d (35, 192) = 1
o Step 3: To determine the private key, we use the following formula to calculate
the d such that:
o ADVERTISEMENT
o Calculate d = de mod φ (n) = 1
o d = d x 35 mod 192 = 1
o d = (1 + k.φ (n))/e [let k =0, 1, 2, 3………………]
o Put k = 0
o d = (1 + 0 x 192)/35
o d = 1/35
o Put k = 1
o d = (1 + 1 x 192)/35
o d = 193/35
o Put k = 2
o d = (1 + 2 x 192)/35
o d = 385/35
o d = 11
o The private key is <d, n> = (11, 221)
o Hence, private key i.e. d = 11
Message Authentication
Verifying the identity of user. Message authentication assures that data recived are
exactly as sent message .
1)Message Encryption:
The Process of conversion of plain text into cipher text, cipher text acts as
authenticator.
We will have some authentication & apply them on plain text along with the key
which produces the fixed length code called MAC. This code is attached to the
message or request sent by the user. Message authentication codes (MACs)
attached to the message must be recognized by the receiving system in order to
grant the user access. MACs are commonly used in electronic funds transfers
(EFTs) to maintain information integrity.
The message authentication code technique involves the use of a secret key. This
technique assumes that two communicating parties, say A and B, share a common
secret key KAB. When A has a message to send to B, it calculates the message
authentication code as a function of the message and the key: MACM = F (KAB,M).
The message plus code are transmitted to the intended recipient. The recipient
performs the same calculation on the received message, using the same secret key,
to generate a new message authentication code. The received code is compared to
the calculated code. If we assume that only the receiver and the sender know the
identity of the key, and if the received code matches the calculate code, then
The receiver is assured that the message has not been altered.
Because no one else knows the secret key, no one else could prepare a
message with a proper code.
If the message includes a sequence number, then the receiver can be assured
of the proper sequence, because an attacker cannot successfully alter the
sequence number.
C(M,K)= Fixed length code(MAC)
Hash Functions
Hashing is the process of generating a value from a text or a list of numbers
using a mathematical function known as a hash function.
The general use of hashing is password checking. When the user enters the
password, the hash of the password is produced and compared with the hash in the
database. If both the hashes are the equal thus the user is enabled to login else the
user required to enter the password again.
Digital signature
A digital signature is a mathematical technique which validates the authenticity and integrity of a
message, software or digital documents. It allows us to verify the author name, date and time of
signatures, and authenticate the message contents.
o Authentication
o Non-repudiation
o Integrity
Authentication
Authentication is a process which verifies the identity of a user who wants to access the system.
In the digital signature, authentication helps to authenticate the sources of messages.
Non-repudiation
Non-repudiation means assurance of something that cannot be denied. It ensures that someone to
a contract or communication cannot later deny the authenticity of their signature on a document
or in a file or the sending of a message that they originated.
Integrity
Integrity ensures that the message is real, accurate and safeguards from unauthorized user
modification during the transmission.
The key generation algorithm selects private key randomly from a set of possible private keys.
This algorithm provides the private key and its corresponding public key.
2. Signing algorithm
The user who is creating the digital signature uses their own private key to encrypt the signature-
related document. There is only one way to decrypt that document is with the use of signer's
public key.
This technology requires all the parties to trust that the individual who creates the signature has
been able to keep their private key secret. If someone has access the signer's private key, there is
a possibility that they could create fraudulent signatures in the name of the private key holder.
It is still much preferred of the two types of encryption systems due to its
simplicity. It is a relatively fast process since it uses a single key for both
encryption and decryption In this encryption model, the sender encrypts
plaintext using the receiver’s secret key, which can be later used by the
receiver to decrypt the ciphertext. Below is a figure that illustrates this
concept.
The idea that uses in this technique is very old and that’s why this model is
called conventional encryption.
Conventional encryption has mainly 5 ingredients :
1. Plain text –
It is the original data that is given to the algorithm as an input.
2. Encryption algorithm –
This encryption algorithm performs various transformations on plain text
to convert it into ciphertext.
3. Secret key –
The secret key is also an input to the algorithm. The encryption algorithm
will produce different outputs based on the keys used at that time.
Ciphertext –
Symmetric Encryption is the most basic and old method of encryption. It uses only
one key for the process of both the encryption and decryption of data. Thus, it is
also known as Single-Key Encryption.
28
Encryption (or E 1. Plain Text (x): This is the original data/message that is to be
communicated to the receiver by the sender. It is one of the inputs to the
encryption algorithm.
There are only two requirements that need to be met to perform encryption.
They are,
Network Security
Network security is the security designed to protect the integrity of the network from
unauthorized access and threats. The network administrators are responsible for
adopting various defensive measures to guard their networks from possible security
risks.
Computer networks are linked in daily transactions and communication within the
government, private, or corporates that needs security. The most common and
straightforward strategy of protecting network support is allocating it with a unique
name and a corresponding password. The network security consists of:
1. Protection: The user should be able to configure their devices and networks accurately.
2. Detection: The user must detect whether the configuration has changed or get a
notification if there is any problem in the network traffic.
3. Reaction: After detecting the problems, the user must respond to them and must
return to a protected position as quickly as possible.
An effective network security model in computer networks has the following key
aspects:
Important Question
32
12. Encrypt the message "Money helps to build
infrastructure" using Hill cipher with the key 9 4 5 7
Show your
calculations and result.
13. Explain Security Services in brief.
33