How to use

This tool is designed to be used to brute force a wide variety of ciphers.

You (probably me, given this site's popularity) must provide code that will become a function that takes 2 parameters:

  1. "ciphertext" is whatever enciphered message you provide in the text box at the top.
  2. "key" is the decryption key that is used to decipher the message.
and will return the decoded text.

The function will be run with every possible value for the key (from 0 to the number provided in the box at the top) and the output of the function will be scored and compared with the previous best score.

Once the function has been run for all values, the best result will be returned to the main thread where the best one will be displayed on the page. They are scored based on the number of English words they contain. This is the step that takes the most resources and will take multiple seconds, or even several minutes, with long cipher-texts or large key spaces.

The exact method of counting depends on the number of keys being tested. For a small number of keys it is faster to iterate over the dictionary and use the '.includes()' method to determine the number of words in the text. For larger keyspaces (more than 1000 currently)To score each result the word list is used to generate a lookup tree and the test iterates over each character in the string to see if it is the start of a word (and if it is, how many words are formed starting at that character).

UPDATE: For simplicity the lookup tree method is used for all tests (preiviously different methods where used depending on keyspace size but this made very little difference to overall speed.).

If you want to see which method is fastest on your machine (or you want a longer explanation) you can run the benchmark I used here (note: this will freeze the tab as it is all run on the main thread. I don't plan to fix this as the code was written late at night and is rather messy. note-2: the recursive version of the new test is used in the actual test.)

The word-list used is the Ubuntu "wbritish" package (with the " 's " versions of words taken out), it has 72,740 words.

Note: to help with the large amount of processing, the work is split between several web workers. This means having more cores in your CPU will have a large impact on performance for longer texts.

helper functions

To make writing decryption functions easier several functions have been defined in the worker for common tasks. These are:

  1. toalph(string) Takes a string and converts each letter into it's position in the alphabet. Punctuation will be unchanged. Both upper and lowercase letters will be converted. The output is returned as an array.
  2. fromalph(array) Takes an array of numbers and characters and converts the numbers to the corresponding letter of the alphabet. Punctuation and existing characters will be unchanged. All converted characters will be uppercase.
  3. isInt(value) Returns true if the value is an integer otherwise returns false. This is useful for ignoring punctuation (most importantly spaces) when using the output of toalph().
  4. words[] This array contains the previously mentioned word list. If a cipher takes a word as the key this can be used to convert the key into a word. e.g. keyword = words[key];

Other cipher decryptors

The default funtion when you load the page is for deciphering Affine ciphers (311 is also the default keysize which is right for Affine).

Vigenère cipher

This also demonstrates how to decode ciphers with word based keys.

A simpler tool for caesar ciphers (old) This site's home page