A One Time Pad is a information-theoretical secure encryption function. But what does that mean?
On a high level the One Time Pad is a simple XOR function that takes the input and xor’s that with a key-stream.
Encryption and decryption are identical.
Some requirements of the One Time Pad are.
Hence, the requirement are only on the key-stream, which obviously is the only input to the algorithm.
The beauty of the algorithm is the simplicity.
The One Time Pad is information-theoretical secure.
That means, that even if the evil adversary had infinite computing power, it could not break it.
The simples way to understand why that is the case is the following. If an adversary catches an encrypted message, which has length, say 10 characters. It can decrypt to any message of length 10.
The reason is, that the key-stream can be anything and is a long as the message itself. That implies, that the plaintext can be possible message of 10 characters.
Obviously, we have a dilemma. We cannot generate a key like that in Python.
The actual implementation of the One Time Pad is done by a simple xor.
def xor_bytes(key_stream, message): return bytes([key_stream[i] ^ message[i] for i in range(length)])
Of course, this requires that the key_stream and message have the same length.
It also leaves out the problem of where the key_stream comes from. The problem is, that you cannot create a key_stream with the required properties in Python.
If you were to receive a message encrypted by a One Time Pad, then for any guess of the plaintext, there is a matching key-stream to get it.
See the code for better understanding it.
def xor_bytes(key_stream, message): length = min(len(key_stream), len(message)) return bytes([key_stream[i] ^ message[i] for i in range(length)]) cipher # cipher is the cipher text # len(cipher) = 10 # If we guess that the plaintext is "DO ATTACK" # Then the corresponding key_stream can be computes as follows message = "DO ATTACK" message = message.encode() key_stream = xor_bytes(message, cipher) # Similar, if we guess the plaintext is "NO ATTACK" # Then the corresponding key_stream can be computes as follows message = "NO ATTACK" message = message.encode() guess_key = xor_bytes(message, cipher)
While One Time Pads are ideal encryption system, they are not practical. The reason is, that there is no efficient way to generate and distribute a true random key-stream, which is only used once and not known by others than sender and receiver.
What will you learn? How to use the modulo operator to check if a number…
There are a lot of Myths out there There are lot of Myths about being…
To be honest, I am not really a great programmer - that is not what…
What will you learn? Need to setup a SQL server? You don’t need to install…