# Avoiding known plaintext attacks with an additional XOR-Layer

Can a cipher that is vulnerable to an known plaintext attack be made secure by adding an additional XOR-encryption?

That is: suppose I have an (w.l.o.g. symmetric) encryption algorithm E were the attacker can retrieve the rest of the message, if he knows any part of it (but secure if he doesn't).

I would try to address this weakness as follows: I would XOR the plaintext with a securely generated 8 byte nonce (used once per message), and then add the nonce as a prefix:

ciphertext = E(key, nonce || XOR(nonce, plaintext))


XOR() applies the nonce repeatedly if the plaintext is longer than 8 byte.

The XORing as such is obviously insecure. But now the attacker doesn't have a known plaintext anymore: He can't know the nonce and therefore can't know "XOR(nonce, plaintext)".

Would this be enough to prevent the known plaintext attack from succeding?

I am not going to implement this, don't worry. I am just curious.

I am also aware that the possibility of an known plaintext attack hints at deeper problems. In reality I would choose another cipher.

• XTS mode might be intersting for you. Basically it is $C=E_K(P \oplus Pad)\oplus Pad$. That sounds similar but won't answer your question I guess. – SEJPM May 11 '15 at 15:29
• Thank you, SOJPM, thats also interesting. But it doesn't answer the question, because I basically am curious if my idea works and if not why. I am not primarily looking for an alternative way to defeat known plaintext attacks. – icehawk May 11 '15 at 17:47