Computer Security Chapter 3
Computer Security Chapter 3
3. Cryptography
3.1 Introduction:
❖ Cryptography:
⚫ Cryptography is technique of securing information and communications through use of codes so
that only those person for whom the information is intended can understand it and process it.
⚫ Cryptography in cybersecurity entails the use of encryption and decryption algorithms.
Converting the plain text (readable text) to cipher text (unreadable text) is called encryption,
and reversing the process i.e cipher text to plain text is called decryption.
⚫ In Cryptography the techniques which are use to protect information are obtained from
mathematical concepts and a set of rule based calculations known as algorithms to convert
messages in ways that make it hard to decode it.
❖ Cryptanalysis :
⚫ Cryptanalysis is the study and process of analyzing and decrypting ciphers, codes, and encrypted
text without using the real key. Alternately, we can say it’s the technique of accessing a
communication’s plain text content when you don’t have access to the decryption key.
⚫ Cryptanalysis is a method of converting ciphertext to plaintext.
⚫ The person practicing Cryptanalysis is called a Cryptanalyst.
⚫ As a cryptanalyst, you are in charge of decoding or decrypting data to understand hidden signals,
even if you do not have the encryption key.
❖ Cryptology :
⚫ Cryptology is the mathematics that underpins cryptography and cryptanalysis, such as number
theory and formula and algorithm application.
⚫ It is the study of conversion of plain text to cipher text and vice-versa. It is also called the study of
Encryption and Decryption.
⚫ It deals with the study of secure communication.
⚫ Cryptology has two parts Cryptography( Encryption) and Cryptanalysis(Decryption).
❖ Substitution techniques:
⚫ An encryption requires two things: 1.Algorithm 2.Key
⚫ There are numerous encryption techniques available for protecting sensitive data.one of them is
Substitution technique.
⚫ A substitution technique is one in which the letters of plaintext are replaced by other letters or by
numbers or symbols.
⚫ If the plain text (original message) is treated as the string of bits, thus the substitution technique
would restore bit pattern of plain text with the bit pattern of cipher text.
1. Caesar’s cipher :
⚫ In this substitution technique, it can encrypt the plain text, each alphabet of the plain text is
replaced by the alphabet three places further it and it can decrypt the cipher text each
alphabet of cipher text is restored by the alphabet three places before it.
⚫ The Caesar cipher is a kind of replacement (substitution) cipher, where all letter of plain text
is replaced by another letter.
⚫ Caesar ciphers is a weak method of cryptography. It can be easily hacked. It means the
message encrypted by this method can be easily decrypted.
◆ Algorithm for Caesar Cipher:
Input:
1. Choose a shift value between 1 and 25.
2. Write down the alphabet in order from A to Z.
3. Create a new alphabet by shifting each letter of the original alphabet by the shift value. For
example, if the shift value is 3, the new alphabet would be:
4. ABCDEFGHIJKLMNOPQRSTUVWXYZ
DEFGHIJKLMNOPQRSTUVWXYZABC
5. Replace each letter of the message with the corresponding letter from the new alphabet. For
example, if the shift value is 3, the word “hello” would become “khoor”.
6. To decrypt the message, shift each letter back by the same amount. For example, if the shift
value is 3, the encrypted message “khoor” would become “hello”.
CT = (p + k) mod 26
PT = (p - k) mod 26
Where,
Encryption
CT = (p+ k) mod 26
By applying formula:
Decryption
PT = (p - k) mod 26
PT = (00 - 15) mod 26
= -15
= -15 + 26
= 11
1. It can be easily hacked. It means the message encrypted by this method can be easily decrypted.
2. It provides very little security.
3. By looking at the pattern of letters in it, the entire message can be decrypted.
❖ Monoalphabetic Cipher :
⚫ A mono-alphabetic substitution cipher is a type of substitution ciphers in which the equivalent
letters of the plaintext are restored by the same letters of the ciphertext.
⚫ Caesar cipher is a type of Monoalphabetic cipher. It uses the similar substitution method to
receive the cipher text characters for each plain text character.
⚫ Mono, which defines one, it signifies that each letter of the plaintext has a single substitute of
the ciphertext.
➢ For instance, if a letter A in the plaintext is changed to D then each appearance of A in the plaintext
will be restored by D.
Plaintext : hello
Ciphertext : IFMMP
This is a monoalphabetic cipher as both l’s are encrypted as ‘M’.
❖ Polyalphabetic Cipher :
⚫ A poly-alphabetic cipher is a cipher based on substitution, using multiple substitution alphabets. It
encrypts plaintext letters differently based on their placement in the text, Rather than being a one-
to-one correspondence, there is a one-to-many relationship between each letter and its
substitutes.
⚫ In polyalphabetic substitution, each appearance of a character in the plaintext can have a different
substitution character in the ciphertext.
⚫ The relationship among a character in plaintext and a character in ciphertext is one to many. For
instance, letter ‘A’ can be restored by the letter ‘C’ and the similar letter ‘A’ can be restored by ‘N’
later in the ciphertext.
⚫ Polyalphabetic ciphers are complex to break due to the absence of plaintext letter frequencies,
making statistical analysis unsuitable for breaking them.
⚫ As the name polyalphabetic recommend this is achieved by using multiple keys rather than only
one key.
⚫ Rail-Fence is the simple Transposition technique that involves writing plain text as a sequence of
diagonals and then reading it row by row to produce the ciphertext.
⚫ Rail fence cipher is easy to implement and even easy for a cryptanalyst to break this technique. So,
there is a need for a more complex technique.
◆ Algorithm :
Step 1: Write down all the characters of plain text message in a sequence of diagnosis.
Step 2: Read the plain text written in step 1 as a sequence of rows.
➢ 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: m e m t m r o
➢ reading the second row of the rail fence, we will get the second half of the cipher text: e t e o o r w
➢ 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
⚫ The columnar transposition cipher is more complex as compared to the rail fence.
⚫ The simple columnar transposition technique can be categorized into two parts – Basic technique
and multiple rounds.
⚫ Simple columnar transposition technique – basic technique. The simple columnar transposition
technique simply arranges the plain text in a sequence of rows of a rectangle and reads it in a
columnar manner.
◆ Algorithm :
Step 1: Write all the characters of plain text message row by row in a rectangle of predefined size.
Note: For reading the message, it needs not to be in the order of columns. It can happen in any random
sequence.
M E E T
T O M O
R R O W
➢ 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. The cryptanalyst only
has to try few permutation and combination over the order of column to obtain the permuted
order of column and the get the original message. So, a more sophisticated technique is required
to strengthen the encryption.
◆ Algorithm :
Step 1: Write all the characters of plain text message row by row in a rectangle of predefined size.
Note: For reading the message, it needs not to be in the order of columns. It can happen in any random
sequence.
Step 4: Repeat the procedure from step 1 to step 3 many times as desired.
M E E T
T O M O
R R O W
➢ 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.
col1 col2 col3 col4
M T R E
O R E M
O T O W
➢ So, the obtained cipher text for round 2 is TRTREOMOOEMW. In this way, we can perform as
many iterations as requires. Increasing the number of iterations increases the complexity of the
techniques.
Method to take key: In the Vernam cipher algorithm, we take a key to encrypt the plain text whose
length should be equal to the length of the plain text.
◆ Algorithm:
1. Assign a number to each character of the plain-text and the key according to alphabetical order.
2. Add each number corresponding to plain-text alphabet number and Key alphabet number.
3. If the sum is greater than 26 ,subtract it from 26.
4. Assign corresponding alphabet to each number of the sum and this gives the output cipher text.
Example:
Plain Text: H E L L O
Key: B A X Y C
➢ Now according to our encryption algorithm we assign a number to each character of our plain-
text and key.
PT: H E L L O
NO: 7 4 11 11 14
KEY: b a x y c
NO: 1 0 23 24 2
➢ Now add the number of Plain-Text and Key and after doing the addition and subtraction operation
(if required), we will get the corresponding Cipher-Text character number.
ADD: 8 4 34 35 16
➢ In this case, there are two numbers which are greater than the 26 so we have to subtract 26 from
them and after applying the subtraction operation the new Cipher text character numbers are as
follow:
SUB: 8 4 8 9 16
➢ New Cipher-Text is after getting the corresponding character from the number.
Cipher Text: I E I J Q
Sender Receiver
⚫ The pair of keys includes a public key, which can be shared with anyone, and a private key,
⚫ In asymmetric encryption, the sender uses the recipient’s public key to encrypt the data. The
⚫ This approach allows for secure communication between two parties without the need for both
Sender Receiver
The size of cipher text is the same or smaller The size of cipher text is the same or larger
than the original plain text. than the original plain text.
The length of key used is 128 or 256 bits The length of key used is 2048 or higher
Data encryption standard (DES) has been found vulnerable to very powerful attacks
DES is a block cipher and encrypts data in blocks of size of 64 bits each, which means 64 bits of plain text go
as the input to DES, which produces 64 bits of ciphertext.
The same algorithm and key are used for encryption and decryption, with minor differences. The key
length is 56 bits.
Since DES is based on the Feistel Cipher, all that is required to specify DES is −
• Round function
• Key schedule
• Any additional processing − Initial and final permutation
Initial Permutation (IP):
• As we have noted, the initial permutation (IP) happens only once and it happens before the first
round.
• It suggests how the transposition in IP should proceed, as shown in the figure.
• For example, it says that the IP replaces the first bit of the original plain text block with the 58th bit
of the original plain text, the second bit with the 50th bit of the original plain text block, and so on.
Key generation:
• 64-bit key is transformed into a 56-bit key by discarding every 8th bit of the initial key.
• The 56-bit key is divided into two halves, each of 28 bits. These halves are circularly shifted left by
one or two positions, depending on the round.
• The round numbers 1, 2, 9, or 16 the shift is done by only one position for other rounds, the circular
shift is done by two positions.
Round function:
The entire 64 bits input in the round contains the left hand side 32 bit and right hand side 32 bit.
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.
• This happens as the 32-bit RPT is divided into 8 blocks, with each block consisting of 4 bits.
• Then, each 4-bit block of the previous step is then expanded to a corresponding 6-bit block, i.e., per 4-
bit block, 2 more bits are added.
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.
Substitution Boxes. –
• The right plain text(output of straight permutation) 32 bits are XOR with the left plain text 32 bits
and placed in the right plain text of next round.
• The right plain text 32 bits(before the round function) are placed in the left plain text 32 bits of next
round.
32 bit swap :
After 16 rounds the LPT 32 bits and RPT 32 bits are swapped.
Final permutation:
Final permutation is a straight permutation.
It is inverse of the initial permutation, it is called inverse initial permutation.
After final permutation, the 64 bit cipher text is ready.
AES algorithm:
The more popular and widely adopted symmetric encryption algorithm likely to be used nowadays is the
Advanced Encryption Standard (AES). It is found at least six time faster than triple DES.
The features of AES are as follows −
• Symmetric key symmetric block cipher
• 128-bit data, 128/192/256-bit keys
• Stronger and faster than Triple-DES
• Vulnerable against exhaustive key search attack
• Software implementable in C and Java
State/matrix:
Data block viewed as 4-by-4 table of bytes
Represented as 4 by 4 matrix of 8-bit byte
Encryption:
Pre- round permutation:
You pass the block data stored in the state array through an XOR function with the first key generated (K0).
It passes the resultant state array on as input to the next step.
Each round comprises of 4 steps :
• SubBytes
• ShiftRows
• MixColumns
• Add Round Key
The last round doesn’t have the MixColumns round.
The SubBytes does the substitution
ShiftRows and MixColumns performs the permutation in the algorithm.
1.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.
This substitution is done in a way that a byte is never substituted by itself and also not substituted by
another byte which is a compliment of the current byte.
2.Shift rows:
This step is just as it sounds. Each row is shifted a particular number of times.
• The first row is not shifted
• The second row is shifted once to the left.
• The third row is shifted twice to the left.
• The fourth row is shifted thrice to the left.
3.MixColumns:
Decryption Process
The process of decryption of an AES ciphertext is similar to the encryption process in the reverse order.
Each round consists of the four processes conducted in the reverse order −
• Add round key
• Mix columns
• Shift rows
• Byte substitution
International Data Encryption Algorithm (IDEA):
The International Data Encryption Algorithm (IDEA) is a symmetric-key block cipher that was first
introduced in 1991.
Features:
• Symmetric block cipher.
• 64 bit block data is used.
• 128 bits key and 52 subkeys are used.
• 8 rounds.
• 6 keys used in each round except the last round.
• In last round 6 + 4 keys are used.
• 3 operations are used: Addition, Multiplication and XOR.
Subkey generation:
• 128 bit key is divided into 8 parts of 16 bits each.
• Then a cyclic left shift is made for 25 positions to get a new 128 bit key.
• The process is repeated until required keys are generated.
The plaintext of 64-bit input block-divided into 4 part (16 bits each) Declare p1 to p4
The p1, p2, p3 and p4 outputs from each round are given as input to the next round, before giving input to
the next round p2 and p3 are swapped.
This swap between 12 and 13 takes place after each complete round, except the last complete round (8th
round)
The p1, p2, p3 and p4 output from the last round are not swapped and are given as input for final
transformation.
The last output created is 4 blocks of ciphertext C1 to C4 as each one of 16 bits and combine them to make
a ciphertext.
Decryption:
Decryption process is similar to encryption algorithm.
But the keys will be used in reverse order and the inverse of the keys are applied.
Asymmetric key cryptography:
RSA Algorithm:
• The RSA algorithm is a public-key signature algorithm developed by Ron Rivest, Adi Shamir, and Leonard
Adleman.
• RSA algorithm is an asymmetric cryptography algorithm. Asymmetric actually means that it works on
two different keys i.e. Public Key and Private Key.
• There are two broad components when it comes to RSA cryptography, they are:
➢ Key Generation: Generating the keys to be used for encrypting and decrypting the data to be
exchanged.
➢ Encryption/Decryption Function: The steps that need to be run when scrambling and recovering
the data.
Step-02:
Calculate ‘n’ and Euler’s totient function Ø(n) where-
• n=pxq
• Ø(n) = (p-1) x (q-1)
Step-03:
Choose any value of ‘e’ such that-
• 1 < e < Ø(n)
• gcd (e, Ø(n)) = 1
Step-04:
Determine ‘d’ such that-
RSA Algorithm:
Let,
Public key of the receiver = (e , n)
Private key of the receiver = (d , n)
Then, RSA Algorithm works in the following steps
Step-01:
At sender side,
• Sender represents the message to be sent as an integer between 0 and n-1.
• Sender encrypts the message using the public key of receiver.
• It raises the plain text message ‘P’ to the eth power modulo n.
• This converts the message into cipher text ‘C’.
Step-02:
• The cipher text ‘C’ is sent to the receiver over the communication channel
Step-03:
At receiver side,
• Receiver decrypts the cipher text using his private key.
• It raises the cipher text ‘C’ to the dth power modulo n.
• This converts the cipher text back into the plain text ‘P’.
Algorithm:
The Diffie-Hellman key exchange works by allowing two parties (Alice and Bob) to agree on a shared secret
key over an insecure channel, without any other party being able to intercept the key or learn anything
about it.
1. Firstly Alice and Bob agree upon two large prime numbers- ‘n’ and ‘g’. These two numbers need not
to be secret and can be shared publicly.
2. Alice chooses another large random number X(private to her).
And calculate ‘A’ such that: A = gX mod n
Alice Bob
• Cryptography uses multiple hash functions to secure data. Some of the most popular cryptographic
hashes include the following:
➢ Secure Hash Algorithm 1 (SHA-1)
➢ Secure Hash Algorithm 2 (SHA-2)
➢ Secure Hash Algorithm 3 (SHA-3)
➢ MD2
➢ MD4
➢ MD5
• The situation where the newly inserted key maps to an already occupied is called collision.
Components of Hashing
There are majorly three components of hashing:
Key: A Key can be anything string or integer which is fed as input in the hash function.
Hash Function: The hash function receives the input key and returns the index of an element in an array
called a hash table. The index is known as the hash index.
Hash Table: Hash table is a data structure that maps keys to values using a special function called a hash
function. Each data value has its own unique index.
Advantages of Hashing:
a) Key-value support: Hashing is ideal for implementing key-value data structures.
b) Fast data retrieval: Hashing allows for quick access to elements with constant-time complexity.
c) Efficiency: Insertion, deletion, and searching operations are highly efficient.
d) Memory usage reduction: Hashing requires less memory as it allocates a fixed space for storing
elements.
e) Scalability: Hashing performs well with large data sets, maintaining constant access time.
f) Security and encryption: Hashing is essential for secure data storage and integrity verification.
Steganography:
• Steganography is the practice of concealing information within another message or physical object to avoid
detection.
• Steganography can be used to hide virtually any type of digital content, including text, image, video, or audio
content.
• That hidden data is then extracted at its destination.
• The use of steganography can be combined with encryption as an extra step for hiding or protecting data.
Text Steganography
• Text Steganography is hiding information inside the text files.
• It involves things like changing the format of existing text, changing words within a text, generating random
character sequences or using context-free grammars to generate readable texts.
Image Steganography
• Hiding the data by taking the cover object as the image is known as image steganography.
• In digital steganography, images are widely used cover source because there are a huge number of bits
present in the digital representation of an image
Audio Steganography
• In audio steganography, the secret message is embedded into an audio signal which alters the binary
sequence of the corresponding audio file.
• Hiding secret messages in digital sound is a much more difficult process when compared to others, such as
Image Steganography.
Video Steganography
• In Video Steganography you can hide kind of data into digital video format.
• The advantage of this type is a large amount of data can be hidden inside and the fact that it is a moving
stream of images and sounds.
• You can think of this as the combination of Image Steganography and Audio Steganography.
STEGANOGRAPHY CRYPTOGRAPHY
Data
Never Always
Visibility
Digital signature:
• A digital signature is a mathematical technique used to validate the authenticity and integrity of a digital
• It's the digital equivalent of a handwritten signature or stamped seal, but it offers far more inherent
security.
• A signature confirms that the information originated from the signer and has not been altered.