I am new to cryptography, and there is one thing that is bothering me. I hope you can kindly help me to understand.

Let's imagine an attacker harvests the plaintext as well the ciphertext from a message that had been encrypted with a One-Time Pad (OTP). I am aware that OTP uses a reverse XOR operation to encrypt the data, but the question is "Is it possible to actually obtain a key by XORing message(plaintext) and ciphertext?".

Note: The encryption was implemented only once.

  • 2
    $\begingroup$ Yes. But discovering the key will not help the attacker, unless the key is not random as it should. If the XOR reveals the first bytes of the key to be "WE, THE PEOPLE OF THE UNI" then the crypto is busted - but that is because it was done wrong. $\endgroup$
    – LSerni
    Commented Oct 14, 2017 at 22:48
  • $\begingroup$ Heads-up: OTP !== stream cipher $\endgroup$
    – e-sushi
    Commented Oct 15, 2017 at 11:33

2 Answers 2


Yes just like you suggest:-

plaintext ⊕ ciphertext = key

but I would question why you'd want to do this? If you have the plaintext, then your attack was successful. You know what the message says. There is no point obtaining the key. A properly organised OTP operation will only use those key bits once for the message you have. They might even then be destroyed /deleted. They should never be needed again so there is no point in having them in the first place. The sender's next message will draw upon new key material. Confused emoji.

Unless, you suspect that the key material is being generated via an algorithm /pseudo random number generator. There are certain people out there who believe that they have discovered an improvement to the venerable OPT. This site has several questions concerning the veracity of clever techniques to avoid using a true random number generator. If you suspect that your sender is one of these confused people, yes there would be value in obtaining the key material in order to attack the generating algorithm. OTP - Reuse key BUT add IV and Hash functions to generate one time pad are good(?) examples of OTP v2 attempts.


"Is it possible to actually obtain a key by XORING message(plaintext) and ciphertext?"

Of course it is; it's actually pretty easy.

On the other hand, those specific key bits were used once; their only use is to protect that specific plaintext; if the attacker learns (by whatever method) what those keybits were, he learns what the plaintext is. If the attacker already knew the plaintext (by whatever method), he doesn't have anything further to gain by learning those specific OTP key bits.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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