mitchell vitez blog music art media dark mode

Ridiculously Inefficient Cipher-cracking in National Treasure 2

The first clue in National Treasure: Book of Secrets involves a Playfair cipher with a five-letter keyword. One of our main characters, Riley Poole, is shown to be guessing words one by one, by hand, to try to crack the cipher. However, in both the prior film and the rest of this one, Riley is characterized as a genius hacker capable of e.g. completely taking over the security system at the National Archives to help Ben Gates steal the Declaration of Independence.

This doesn’t make any sense.

Assuming the five-letter keyword could be any combination of five letters, there are at most \(26^5\) combinations to check. This comes out to 11,881,376 words. On my modern (2021) laptop, enumerating through these words takes just a few lines of code and less than ten seconds.

import itertools
import string

for x in itertools.product(string.ascii_uppercase, repeat=5):
    print(''.join(x))

If we look back at CPUs from the mid 2000s though, they’re also quite capable of getting through this wordlist in a speedy fashion. For example, the Pentium D 950 runs at 3.4 GHz. I’m not sure what CPU Riley was using, but I think it’s fair to once again assume that an expert hacker has a decent setup.

We can do way better than this enumeration if we take a quick look at the dictionary and filter for actual five-letter words.

with open('/usr/share/dict/words') as wordlist:
    for word in wordlist.readlines():
        word = word.replace('\n', '')
        if len(word) == 5:
            print(word)

The resulting wordlist has only 10,239 words. Writing a little script, sorting by likelihood to be a real result, and relying on Ben Gates’ knowledge of history to pick out a final result seems a lot more time-efficient than having Riley plug in individual words alphabetically.