Last active
August 29, 2015 14:01
-
-
Save slopjong/9f4266680348ab196a7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// with permutations of 'matrix' the encrypted text couldn't be decrypted | |
// there are more 6 char long names, see the following list: | |
// http://de.wikipedia.org/wiki/Matrix_%28Film%29#Synchronisation | |
// !! these are the German names !! | |
$initial_guess = "matrix"; | |
function permutate($input) { | |
$guesses = array(); | |
if (strlen($input) > 1) { | |
$first_char = $input[0]; | |
$permutations = permutate(substr($input, 1, strlen($input))); | |
foreach($permutations as $permutation) { | |
$guesses[] = strtolower($first_char) . $permutation; | |
$guesses[] = strtoupper($first_char) . $permutation; | |
} | |
} else { | |
$guesses[] = strtolower($input); | |
$guesses[] = strtoupper($input); | |
} | |
return $guesses; | |
} | |
function replace_chars_on_position(array $permutations, $substitutes) { | |
$arr = array(); | |
foreach ($permutations as $permutation) { | |
foreach ($substitutes as $substitute) { | |
foreach ($substitute as $sub) { | |
$permutation_to_be_changed = $permutation; | |
$permutation_to_be_changed[$sub->position] = $sub->symbol; | |
$arr[] = $permutation_to_be_changed; | |
} | |
} | |
} | |
return $arr; | |
} | |
$l33t_substitutions = <<<JSON | |
[ | |
[ | |
{ "position": 1, "symbol": "4" } | |
], | |
[ | |
{ "position": 4, "symbol": "1" } | |
], | |
[ | |
{ "position": 1, "symbol": "4" }, | |
{ "position": 4, "symbol": "1" } | |
] | |
] | |
JSON; | |
$permutations = permutate($initial_guess); | |
$permutations = array_merge( | |
$permutations, | |
replace_chars_on_position($permutations, json_decode($l33t_substitutions)) | |
); | |
$encrypted = "yptyoDdVBdQtGhgoePppYHnWyugGmy0j81sf3zBeUXEO/LYRw+2XmVa0/v6YiSy9Kj8gMn/gNu2I7dPmfgSEHPUDJpNpiOWmmW1/jw/Pt29Are5tumWmnfkazcAb23xe7B4ruPZVxUEhfn/IrZPNZdr4cQNrHNgEv2ts8gVFuOBU+p792UPy8/mEIhW5ECppxGIb7Yrpg4w7IYNeFtX5d9W4W1t2e+6PcdcjkBK4a8y1cjEtuQ07RpPChOvLcSzlB/Bg7UKntzorRsn+y/d72qD2QxRzcXgbynCNalF7zaT6pEnwKB4i05fTQw6nB7SU1w2/EvCGlfiyR2Ia08mA0GikqegYA6xG/EAGs3ZJ0aQUGt0YZz0P7uBsQKdmCg7jzzEMHyGZDNGTj0F2dOFHLSOTT2/GGSht8eD/Ae7u/xnJj0bGgAKMtNttGFlNyvKpt2vDDT3Orfk6Jk/rD4CIz6O/Tnt0NkJLucHtIyvBYGtQR4+mhbfUELkczeDSxTXGDLaiU3de6tPaa0/vjzizoUbNFdfkIly/HWINdHoO83E="; | |
$encrypted = base64_decode($encrypted); | |
$iv = "DkBbcmQo1QH+ed1wTyBynA=="; | |
$iv = base64_decode($iv); | |
// no we walk through all the permutations of 'matrix' (with l33t included) | |
foreach ($permutations as $key) { | |
// extend the key by the 26 known bytes | |
for ($j=0; $j<26; $j++) { | |
$key .= "\0"; | |
} | |
echo $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment