-1
$\begingroup$

very new to crypto-stuff, i have to write a program in C that compute key(k) used in RC4 when I know open text(p) and ciphered(c) text

so I have c_1=p_1 XOR k. How do I compute key from this? What is the "inverse" operation to XOR ?

$\endgroup$
2
  • 2
    $\begingroup$ XOR is the inverse of XOR. $\endgroup$ – SEJPM Mar 30 '16 at 21:40
  • $\begingroup$ so i do p xor c = k ? or c xor p = k $\endgroup$ – lllook Mar 30 '16 at 21:48
2
$\begingroup$

You're given $c,p$ and are challenged to find $k$ using the relation $c=p\oplus k$ (where $\oplus$ denotes bit-wise XOR).

As the inverse operation of XOR is, well, XOR, you can recover $k$ by computing $k=p\oplus c=c\oplus p$.


You may be wondering a) why is XOR the inverse of XOR and b) why is XOR commutative (e.g. $a\oplus b=b\oplus a$).

For b), we need the truth table of XOR:

Input 1 | Input 2 | Output
--------+---------+-------
   0    |    0    |   0   
--------+---------+-------
   0    |    1    |   1   
--------+---------+-------
   1    |    0    |   1   
--------+---------+-------
   1    |    1    |   0   

and you can clearly see, that XOR is commutative, as the same input always results in a "1" and a different input (no matter where it comes from) always results in a "0".

As for a), we need to see that $c\oplus p = k \oplus p \oplus p = k$, e.g. that $a\oplus a=0$ and that $a\oplus 0=a$ which is trivial to see given the above truth table, as you can clealy observe that the same input bit always results in a zero and any input always results in itself if paired with a zero.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.