I have searched and my problem is exactly the same as shown here:
Decrypt simple CBC message with known IV using XOR encryption
However, when I implement the solution it doesn't work, neither does my own solution.
I will restate the problem:
I've been given a ciphertext message, encrypted using CBC. I know that the block size is 12 bytes and I know the plaintext value of the first block.
I also know that the encryption function is a simple XOR:
Ci=K⊕(Mi⊕Ci−1) where C0=IV.
My (incorrect) solutions, programmed in Java:
Terminology:
"encrypted" is a byte-array holding the ciphertext
"decrypted" is a byte-array holding the recovered plaintext (decrypted cipher)
"first_block" is a byte-array holding the decrypted first block (which is the IV)
"key" is a byte-array, which will hold the key after it is recovered
^ is the java expression for XOR
The IV is known
attempt 1, using my own imagination:
// corresponds to K = IV (+) C0, where C0 = K (+) IV
for (int i = 0; i < 12; i++)
key[i] = (byte) (first_block[i] ^ encrypted[i]);
// corresponds to K (+) Ci (+) Ci-1
for (int i = 12; i < 24; i++)
decrypted[i] = (byte) (key[i-12] ^ encrypted[i] ^ encrypted[i-12]);
Result: I decrypt the first block of twelve, which is the IV that I already know, but the second block is just gibberish
attempt 2, using the information gotten from the previous question linked above copied:
//K = C0 + C1 + M1
byte[] key = new byte[12];
for (int i = 0; i < 12; i++)
key[i] = (byte) (encrypted[i] ^ encrypted[i+12] + first_block[i]);
// Mi = K + Ci + Ci-1
byte[] decrypted = new byte[encrypted.length];
for (int i = 12; i < 24; i++)
decrypted[i] = (byte) (key[i-12] ^ encrypted[i] ^ encrypted[i-12]);
Result: Still just gibberish, but different gibberish that I got above
What I'm looking for: Any kind of help