Home XOR known-plaintext attack
Post
Cancel

XOR known-plaintext attack

XOR cipher is a type of additive cipher extremely common as a component in more complex ciphers.

XOR cipher can trivially be broken using frequency analysis, and, if the content of any message can be guessed or, otherwise, known then the key then can be revealed.

The XOR cipher is vulnerable to a known-plaintext attack (KPA) since:

plaintext ⊕ ciphertext = key

It’s also trivial to flip arbitrary bits in the decrypted plaintext by manipulating the ciphertext. This is called malleability.

Known-plaintext attack explained

If we can guess, or we know, the initial plain text string (or at least a part of it) and we know the result ciphertext we can guess the key used to encrypt. Once we get the key we can get the initial plain text string only reapplying the XOR function with the guessed key to the ciphertext:

Plaintext ⊕ Key = Ciphertext → Ciphertext ⊕ Key = Plaintext

I wrotte a little pyhton script to show how this attack works and I added it to my collection of python examples. You can take a look at the example in https://github.com/rubenhortas/python_examples/blob/master/cryptography/xor_kpa.py

Enjoy! ;)

This post is licensed under CC BY 4.0 by the author.