In cryptography, the one-time pad (OTP) is an encryption technique that cannot be cracked, but requires the use of a one-time pre-shared key the same size as, or longer than, the message being sent. It satisfies the perfect-secrecy's requirements.
P(M=m|C=c)=P(M=m)
i.e. seeing a ciphertext doesn't give you any extra information about the plaintext. The probability of seeing a message m after the ciphertext has been observed is the same as the probability of the message without the ciphertext.
Let us see what goes wrong when a "one-time" pad is used more than once.
The file "ciphertexts.txt" contains some hex-encoded ciphertexts that are the result of encrypting some ASCII messages with the same pad.
Note:
- Cleartext messages contain only letters and spaces
- The key idea to crack this code is considering what happens when a space is XORed with a (uppercase/lowercase) letter
The idea for this exercise has been taken from the excellent course "Cryptography I" on Coursera (https://www.coursera.org/course/crypto)
Using Python to tackle the challenge, you may find the following resources useful:
https://docs.python.org/3/library/argparse.html
https://docs.python.org/3/library/binascii.html
https://docs.python.org/3/library/stdtypes.html#string-methods
https://docs.python.org/3/library/functions.html#func-range
https://docs.python.org/3/library/functions.html#enumerate
https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations