Score:1

# Reversing an XOR encryption/decryption function

I have a help recommended high-school project that I'm stuck with. To basically explain the problem: I have an encryption function that is used as the decryption function and I need to reverse it to make an encryption function.

I tried many things but I can't find the proper result. The best I came with was to encrypt 1 byte on 2 properly.

Here is the core of the function (the rest is variables initialization:

// Decrypt
for (i = 0; i < 256; i++) {
decrypted_msg[i] = (xor_key[i % 128] - i) ^ (encrypted_msg[i] - i / 16 - 12);
}


So can someone explain me (like I'm five) how to reverse this code to produce the encryption?

Thank you by advance for help.

Score:1

decrypted_msg[i] = (xor_key[i % 128] - i) ^ (encrypted_msg[i] - i / 16 - 12);

convert this into equations

\begin{align} p[i] &= (\phantom{(}key[i \bmod 128]-i) \oplus (c[i] - i/16 -12)\\ c[i] - i/16 -12 &= (\phantom{(}key[i \bmod 128]-i) \oplus p[i]\\ c[i] - i/16 &= \left( (key[i \bmod 128]-i) \oplus p[i] \right) +12\\ c[i] &= \left( (key[i \bmod 128]-i) \oplus p[i] \right) +12 +i/16 \end{align}

Thanks a lot, it worked flawlessly. And big thank for the equations!
You can edit my answer and take the $\LaTeX$ code, too. What kind of project is this on what kind of school?
I'm in normal highschool in France, it's a project about reversing communication protocol at my school's computer club.
I hope getting help was not prohibited
No, don't worry. It's even recommended. :)
I sit in a Tesla and translated this thread with Ai: