# CBC

When AES is used in **CBC mode**, each block of **plaintext is first XORed with the previous block of ciphertext** (or the IV, in the case of the first block). This XOR operation ensures that even **if two plaintext blocks are identical, the corresponding ciphertext blocks will be different**. The result of the XOR operation is then encrypted using AES with the shared secret key.

Decryption works in the opposite order. Each block of ciphertext is first decrypted using AES with the shared secret key, producing the corresponding block of plaintext. This block is then XORed with the previous block of ciphertext (or the IV, in the case of the first block), producing the original plaintext.

<figure><img src="https://github.com/Hakumarachi/theCTFRecipe/blob/master/.gitbook/assets/Schema_cbc.png" alt=""><figcaption><p>CBC mode encryption</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.ctfrecipes.com/cryptography/symmetric-cryptography/aes/mode-of-operation/cbc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
