Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction 
2.
Modes of Operations in Block Cipher
2.1.
Electronic Code Block (ECB)
2.2.
Cipher Block Chaining
2.3.
Cipher Feedback Mode (CFB Mode)
2.4.
Output Feedback Mode (OFB Mode)
2.5.
Counter Mode (CTR mode) 
3.
Frequently Asked Questions
3.1.
What is the Block Cipher method? 
3.2.
What is the difference between Cipher Feedback Mode and the Output Feedback Mode? 
3.3.
What is the difference between Electronic Code Block and Cipher Code Training? 
4.
Conclusion
Last Updated: Mar 27, 2024
Easy

Introduction to Modes of Operations

Author Neha Chauhan
1 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction 

Cryptography is the technique of converting a text that humans can easily read into a cryptic text that humans cannot understand without decoding it. There are many algorithms to convert normal text into cryptic text; such an algorithm is called Cipher. This is done to secure information exchange and communication. 

Encryption is the process of converting normal (human-readable) text into coded text that is not in understandable human form. Decryption is the process of conversion of the cryptic text back into human-readable form. 

Block cipher, as the name suggests, is an encryption technique in which the input plain text is divided into blocks of equal size (say bits), and blocks of cyphertext of size equal to the plain text are generated. 

Introduction to modes of operations

In this article, we will discuss the modes of operations in Block Cipher i.e. methods for converting block plain text into cipher plain text. 

Modes of Operations in Block Cipher

As mentioned above, Block cipher is a technique in which plain text is encrypted by dividing the text into blocks of equal size, producing blocks of cryptic text of the same size as the plain text. 

There are five modes of operation of Block Cipher; let’s discuss them - 

Electronic Code Block (ECB)

This is the simplest Block cipher method. This method simply converts the plain text into blocks of equal size. After this, we apply the encryption algorithm to them and create cipher text of equal block sizes. 

👍 Advantage 

This method is very simple. The plain text will be converted directly into cipher text.

Many blocks of plain text can be encrypted parallel to each other, thus making the process faster. 

👎 Disadvantage 

Even though it is a simple method, this method is not used practically. The main disadvantage is that in the case of repetitive plain text, the cipher text will also be repetitive, leading to low-quality cryptic text. 

Cipher Block Chaining

Chaining is the process of connecting the present object with the previous object. 

Cipher block chaining is also a type of Block chaining so the plain text is converted into blocks of text that are then encrypted. 

In Cipher Block Chaining, we XOR the previous block's cipher text with the current block's plain text before applying the encryption algorithm. 

Since, there will be no previous state for the first block, create an Initialization Vector (IV). Calculate the XOR of this Initialization Vector and Plain text and apply the encryption algorithm on the result to create the cipher text. 

The size of the Initialization Vector is equal to the size of each block of plain text. 

👍Advantage  

1️⃣ All the blocks are connected to each other, so if the value in any of the blocks is changed then all the values in subsequent blocks will also be affected. Hence, the Cipher Block Chaining method can be used for authentication purposes

2️⃣ It will generate different cryptic text for repetitive plain text, thereby overcoming the disadvantage of the Electronic Code Block mode. 

👎 Disadvantage

As all the block phases are connected to each other, parallel encryption is NOT possible in Cipher Block Chaining. 

Cipher Feedback Mode (CFB Mode)

The steps followed in this Mode are as follows - 

✔️In this method, for the initial phase, an Initiation Vector (IV) of length ‘b’ bits is created and fed to the Shift Register.

✔️ This shifted value is then encrypted using a key ‘k.’ 

✔️ The encrypted value is divided into two parts of size ‘s’ bits and ‘b-s’ bits. The left-hand side ‘s’ bits are XORed with the ‘s’ bits of the plaintext, and the cipher text is produced. 

✔️ The resultant cipher text is given as an input to the shift register having ‘b-s’ bits to the left-hand side and the ‘s’ bits to the right-hand side, and the process continues. 

👍 Advantage 

Some data is lost because of the left shift operation, so it is difficult to apply cryptanalysis.

👎 Disadvantage 

Each phase is dependent on the output of the previous phase. Hence parallel encryption is not possible. 

Output Feedback Mode (OFB Mode)

This mode is similar to the Cipher Feedback Mode. There are two differences - 

1️⃣ Unlike the Cipher Feedback Mode, in Output Feedback Mode, the output encrypted text is sent as the input to the next phase instead of the final cipher text created by XOR between the plain text and the encrypted text. 

2️⃣ The second difference is that the entire encrypted text is used to create the final cipher text instead of choosing only ‘s’ bits like in the Cipher Feedback Mode. 

So, the steps of this mode are as follows - 

✔️In this method, for the initial phase, an Initiation Vector (IV) of length ‘b’ bits is created and fed to the Shift Register.

✔️This shifted value is then encrypted using a key ‘k’. 

✔️This encrypted text is sent as input to the next phase. 

XOR operation is performed between the plain text and the entire length of the encrypted text and the cipher text is generated. 

👍 Advantage 

In the case of CFB, a single-bit error in a block is propagated to all subsequent blocks. OFB solves this problem as it is free from bit errors in the plaintext block. 

👎 Disadvantage

It is more prone to message stream modification attacks. 

Counter Mode (CTR mode) 

In this mode, a counter-initiated value is created for every phase. This counter-initiated value is encrypted. 

This encrypted value is given as an input to the XOR operation with plain text, and a ciphered text is generated. 

A new counter-initiated value is used in every phase. Hence we can apply parallel encryption. 

👍 Advantage

As each phase is independent of the next phase, parallel encryption is possible. 

👎 Disadvantage

A synchronous counter is required. In the absence of this synchronous counter, the value of the plaintext will be changed. 

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Frequently Asked Questions

What is the Block Cipher method? 

The Block cipher method is an encryption and decryption technique in which the plain text is encrypted by dividing the text into blocks of equal size, producing blocks of cryptic text of the same size as the plain text. 

What is the difference between Cipher Feedback Mode and the Output Feedback Mode? 

The Cipher Feedback Mode and the Output Feedback Mode are very similar but there are two differences between them - the first difference is that in Output Feedback Mode, the encrypted text is given as input to the next phase, unlike the cipher text in the Cipher Feedback Mode and the second difference is that the encrypted message is NOT divided into any parts in case of Output Feedback Mode. 

What is the difference between Electronic Code Block and Cipher Code Training? 

In the case of an Electronic Code Block, the phase is independent of each other, while in Cipher Code Training, the output cipher text of the previous block is given as an input for the XOR operation with the plain text. 

Conclusion

Pat yourself on the back👏 for finishing this article. In this article, we discussed what Block Cipher is and the different modes of Block ciphering. We discussed the advantages and disadvantages of each mode. 

Do not stop learning! We recommend you read these articles - 

🔥 What is Cryptography?

🔥 What are basic Cryptography tools?

🔥 Message Authentication Codes in Cryptography

🔥 Security in Cryptography


Head to the Guided Path on the Coding Ninjas Studio and upskill in Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more courses.

If you want to Practice top Coding Problems, attempt mock tests, or read interview experiences, head to the Coding Ninjas Studio, our practice platform.

We wish you Good Luck!🎈 Please upvote our blog 🏆 and help other ninjas grow.

Previous article
Advancing the Data Encryption Standard
Next article
What are Stream Ciphers?
Live masterclass