Cracking the Cryptex with PHP

In the book “the Davinci Code” there was a fun little device called a cryptex.. A Cryptex has 6 dials with 6  letters on each, and only one combination producing a word will open it. The most straight forward way to crack it would be to try every combination one by one, but there’s a substantial number of combinations and we know only those which a valid words is a candidate.

With PHP, a few nested loops and the aspell interface available, cracking the code is simple matter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$pspell_link = pspell_new("da"); // Bring in the dictionarry
 
$array1 = Array("K", "M", "A", "D", "T", "J");  // First dial
$array2 = Array("B", "H", "R", "W", "Y", "E");
$array3 = Array("S","O","L","F","V","C");
$array4 = Array("X","T","N","U","Z","P");
$array5 = Array("E","D","Z","T","G","I");
$array6 = Array("N","G","L","D","Q","K");
 
foreach ($array1 as $a1) {
foreach ($array2 as $a2) {
foreach ($array3 as $a3) {
foreach ($array4 as $a4) {
foreach ($array5 as $a5) {
foreach ($array6 as $a6) {
$word = $a1 . $a2 . $a3 . $a4 . $a5 . $a6;
if (pspell_check($pspell_link,$word)) { // is the word in the dictionary?
echo $word;
echo "<br>";
}
}
}
}
}
}
}
 
exit();

This script prints out a list of all valid (Danish) words, that can occur with the given combination of letters.

  • Not necessarily… I often write elaborate puzzles or riddles where the first letter of each answer represents the letter on the corresponding code ring. Or sometimes I use the first letter of each word in a phrase or song.

    That way the “password” is not really a word, but appears to be a set of random letters such as OSCYS or FXRMB

  • Not necessarily… I often write elaborate puzzles or riddles where the first letter of each answer represents the letter on the corresponding code ring. Or sometimes I use the first letter of each word in a phrase or song.

    That way the “password” is not really a word, but appears to be a set of random letters such as OSCYS or FXRMB

  • Not necessarily… I often write elaborate puzzles or riddles where the first letter of each answer represents the letter on the corresponding code ring. Or sometimes I use the first letter of each word in a phrase or song.

    That way the “password” is not really a word, but appears to be a set of random letters such as OSCYS or FXRMB