Finding the IV of AES CBC (CTF) We have a python program that encrypts/decrypts plaintext given in hex to a cipher using AES CBC. We know that the IV is the same and is not going to change (it is stored in a file). How can we possibly find the IV, if found this will be the flag.
Request decryption for three blocks ( 2 is enough);
\begin{align}
P_1 =&amp; Dec_k(C_1) \oplus IV\\
P_2 =&amp; Dec_k(C_1) \oplus C_{0}\\
P_3 =&amp; Dec_k(C_2) \oplus C_{1}\\
\end{align}
Now remove the first ciphertext, and request decryption;
\begin{align}
P'_2 =&amp; Dec_k(C_1) \oplus IV\\
P_3 =&amp; Dec_k(C_2) \oplus C_{1}\\
\end{align}
Now use the equations of $P_2$ and $P'_2$
$$\begin{align}
P_2 \oplus P'_2 &amp;= Dec_k(C_1) \oplus C_{0} \oplus Dec_k(C_1) \oplus IV\\
&amp; = C_{0} \oplus IV \\
P_2 \oplus P'_2 \oplus  C_{0} &amp;= IV \\
\end{align}$$

In programmer aspect
defn CBCDecryptionOracle(c[]):
   return Dec(c[])

c = (c1,c2)

p1 = CBCDecryptionOracle(c)

d = c[0]

p2 = CBCDecryptionOracle(d)

print( p1[0] ^ p2 ^ c0)