purpose: Caesar Cipher Cracker
version: v1.0
creator: Dr MindHacker [Cory Michael Boston]
contact: [drmindhaxor]@yahoo.com
define("WORDS", 640); $cword; $lens; $syms; $alphabet = "abcdefghijklmnopqrstuvwxyz"; /************************************************** tests each rot result against words in list of that length **************************************************/ function WordSeek($letters, $word) { $dict; $match = 0; $result = 0; $searching = 1; $source; $path = "dict/"; $path .= $letters; $path .= ".TXT"; $dict = fopen($path, "r"); while($searching) { $match = 0; $source = fgets($dict); if(!$source) { $searching = 0; } else { rtrim($source); if($word[1] == $source[1]) { for($x = 0; $x < $letters; $x++) { if($word[$x] == $source[$x]) { $match++; } } if($match == $letters) { $result = 1; $searching = 0; } } } } fclose($dict); return $result; } /************************************************ rotate the letter ************************************************/ function Rotate($letter, $rot) { $wrapper = 0; global $alphabet; for($x = 0; $x < 26; $x++) { if($letter == $alphabet[$x]) { if(($x + $rot) >= 25) { $letter = $alphabet[$rot - 1]; } else { $letter = $alphabet[$x + 1]; } $x = 26; } } return $letter; } /************************************************ convert one word at a time and test to see if rot matches a word in dictionary - if first two match use that rot to decrypt rest of text ************************************************/ function ROTBruteForce() { $rot = 1; $key = 0; $letter = 0; $letters = 0; $comparing = 1; $cracking = 2; $cracked = 0; $result = 0; $sym = 0; $word = ""; global $cword; global $lens; for($rot; $rot < 26; $rot++) { if(!$cracked) { $comparing = 1; $cracking = 2; while($comparing) { if($letter = $cword[$sym][$letters]) { $word .= Rotate($letter, $rot); $letters++; if(($cracked) && ($letters == $lens[$sym])) { //echo "$word "; $letters = 0; $sym++; $word = ""; } else if(($cracking) && ($letters == $lens[$sym])) { $result = WordSeek($letters, $word); $letters = 0; if($result) { $cracking--; //echo "$word "; $word = ""; $sym++; if(!$cracking) { $cracked = 1; } } else { $comparing = 0; continue; } } } else { $comparing = 0; } } } } return 0; } /************************************************ main loop ************************************************/ //echo Clear Text: global $cword; global $lens; global $syms; $cword = preg_split("/[\s]+/", $_POST['CIPHER']); for($x = 0; $x < WORDS; $x++) { $lens[$x] = strlen($cword[$x]); $cword[$x] = strtolower($cword[$x]); if($lens[$x] == 0) { $syms = $x; $x = WORDS; } } ROTBruteForce();