# Bit flipping

A Bit Flipping Attack is a type of attack where an attacker modifies the ciphertext in such a way that it results in a specific change in the decrypted plaintext. In the case of AES CBC, the attacker can modify specific bits in the ciphertext to flip the corresponding bits in the decrypted plaintext.

## How it works ?

In AES CBC, **each block of plaintext is XORed with the previous block of ciphertext** before being encrypted.

This means that **if an attacker modifies a bit in the ciphertext of one block**, it will result in the corresponding <mark style="color:red;">**bit in**</mark> <mark style="color:red;">t</mark><mark style="color:red;">**he decrypted plaintext of the next block being flipped**</mark>. This is because the modified ciphertext block will be XORed with the next block of plaintext during decryption, resulting in the bit flip.

In order to determine the value to puts as ciphertext to flip to an arbitrary value the following operation can be done :

```python
xor(ciphertext_block, original_data, arbitrary_value)
```


---

# 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/bit-flipping.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.
