# Cipher Block Chaining (CBC) in Cryptography

**Cryptography | Cipher Block Chaining (CBC)**: This article is about the Cipher Block Chaining. In this article, we will briefly study the basic CBC and its examples aim to capture. We will cover types of messages in **Cipher Block Chaining**.

Submitted by Monika Sharma, on February 13, 2020

This is a **Cipher block chaining (CBC)** is a cryptography mode of operation for a block cipher (one in which a sequence of bits are encrypted as a single unit or a block with a ciphertext or encrypted key applied to the entire block of the cryptography). Cipher block chaining uses what is known as an initialization vector (IV) of a certain length of a character. There are one of its key characteristics is that it uses chaining the working mechanism that causes the decryption of a block of ciphertext to depend on all the preceding ciphertext blocks. As a result, the entire validity of all preceding blocks is contained in the cryptography immediately previous ciphertext block. A single-bit error of the cryptography in a ciphertext block affects the decryption of all subsequent blocks. Rearrangement of the order of the ciphertext blocks causes with this decryption to become corrupted. Basically, in cipher block chaining, each plaintext block is XORed (see XOR) with the immediately previous ciphertext block and then encrypted of the cryptography.

They are the identical ciphertext blocks can only give the result if the same plaintext or original text block is encrypted using both the same encrypted key and the initialization vector(IV), and if the ciphertext block order is not changed or rearranged. It has the advantage over the Electronic Code Book mode in that the XOR'ing process hides plaintext patterns in this way.

The initialization vector(IV) should be different for any two messages encrypted with the same cryptography key. Though the initialization vector need not be secret or placed, some applications may find this desirable and different.

Cipher block chaining or **CBC** is an advanced or better made on ECB since ECB compromises some security or privacy requirements. In the CBC, the previous cipher block is given as input to the next encryption algorithm after XOR with an original plaintext block of the cryptography. In a nutshell here, a cipher block is produced by encrypting an XOR output of previous cipher block and present plaintext or original text block.

The process is illustrated here,

Image source: https://www.geeksforgeeks.org/block-cipher-modes-of-operation/

### Advantages of CBC

- This is a CBC that works well for input greater than b bits.
- CBC is the best authentication mechanism for this.
- Better resistive nature towards cryptanalysis than ECB in the process.

### Disadvantages of CBC

- This is the parallel encryption is not possible since every encryption requires the previous cipher of the cryptography.

### Example

We can let's look at applying CBC. Let's start with a message of **"bred"**, and a key of **"bert"**, and use and IV of 1 as which gives: **"1AC9C54C951E180E0000000000000000"**.

Next, we'll change to an IV of 2: which gives, **"D27FA68C6AC794200000000000000000"**

Then, Next, we will apply it to 3DES, which uses a 112-bit key, and an IV value which is 8 bytes. Let's take an example with a message of:

The message is"The quick brown dog jumped over the lazy fox". and a key of:1234567890123456ABCDEFGHIf we use an IV of"12345678"we get the point:E6B6345F1015380284481BBCFFB9052A227FC14F73072E8D5 007AC01DFEDCC2BCBCE1EB14A95ED60BA1A44700F4E18AEbut if we use this IV of "23456789" we can get the way5BF29657E6064EB99E52ACC8E3A6808A761A86A7EE85C25C 327022C30D939D3A8A41A9CD42689AA4481FF20155816A8CSo, at least, it will change of different IV values for the cryptography.

### Security Challenge

The main feature of this scheme of encryption is that identical blocks of the clear text belong to one message, are ciphered into various blocks of ciphertext.

Here are the main characteristics of this scheme are,

- If one bit of the transferred message will be corrupted or destroyed, it will damage the one more particular block. Other blocks would be safe from this damage.
- Case of loss or an insert at least one bit into ciphertext, there will be a shift of bits and borders of blocks that will lead to wrong decryption of all subsequent blocks of ciphertext of the cryptography.
- The factor can add blocks by the end of the ciphered message, supplementing with that a clear-text or original text.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions