Hacking Secret Ciphers with Python

(Ann) #1
Chapter 22 – The One-Time Pad Cipher 359

know that if a key decrypts the first ciphertext to readable English, but that same key decrypts the
second message to random garbage text, it must not be the original key. In fact, it is highly likely
that there is only one key that will decrypt both messages to English.


If the hacker only had one of the two messages, then it is still perfectly encrypted. But, you must
always assume that all of your encrypted messages are being intercepted by hackers and/or
governments (otherwise, you wouldn’t need to bother encrypting your messages.) Remember
Shannon’s Maxim: The enemy knows the system! This includes knowing the ciphertext.


The Two-Time Pad is the Vigenère Cipher


To see why the two-time pad is hackable just like the Vigenère Cipher, let’s think about how the
Vigenère cipher works when it encrypts a message that is longer than the key. Once we run out of
characters in the key to encrypt with, we go back to the first character of the key and continue
encrypting. So to encrypt a 20-character message like “AABBCCDDEEVVWWXXYYZZ” with
a 10-character long key such as “PRECOCIOUS”, the first ten characters (AABBCCDDEE) are
encrypted with “PRECOCIOUS” and then the next ten characters (VVWWXXYYZZ) are also
encrypted with “PRECOCIOUS”.


Plaintext AABBCCDDEEVVWWXXYYZZ^
Vigenère Key PRECOCIOUSPRECOCIOUS^
Vigenère Ciphertext PRFDQELRYWKMAYLZGMTR^

We have already learned how to break Vigenère ciphers. If we can show that a two-time pad
cipher is the same thing as a Vigenère cipher, then we can prove that it is breakable using the
same techniques used to break Vigenère cipher.


Using the one-time pad cipher, let’s say the 10-character message “AABBCCDDEE” was
encrypted with the one-time pad key “PRECOCIOUS”. Then the cryptographer makes the
mistake of encrypting a second 10-character message “VVWWXXYYZZ” with the same one-
time pad key, “PRECOCIOUS”.


Message 1 Message 2
Plaintext AABBCCDDEE^ VVWWXXYYZZ^
One-Time Pad Key PRECOCIOUS^ PRECOCIOUS^
One-Time Pad Ciphertext PRFDQELRYW^ KMAYLZGMTR^

If we compare the ciphertext of the Vigenère cipher and the ciphertexts of the one-time pad
cipher, we can see they are the exact same. The two-time pad cipher has the same properties as
the Vigenère cipher, which means that the same techniques could be used to hack it!


This also tells us that if we do the Vigenère cipher but use a key that is as long as the message it
is encrypting (and only use this key once for this message), then it will be perfectly unbreakable.

Free download pdf