_inputString = $inputString; $this->_expectedString = array( $expectedString, strtolower($expectedString), strtoupper($expectedString), strrev($expectedString) ); $this->_writeToFile = $writeToFile; $this->_testStrings(); } /** * Test various hash algorithms on strings. * * @access protected * @void */ protected function _testStrings() { if ($this->_writeToFile) { file_put_contents('hash_matches.txt', ''); } $firstArray = $this->_hashesToArray($this->_inputString); $secondArray = []; foreach ($firstArray as $key => $value) { if (!$this->_writeToFile) { if (in_array($value, $this->_expectedString)) { exit( '[' . $this->_inputString . ']=>[' . $key . ']=>' . $value . ']' . PHP_EOL ); } } else { file_put_contents('hash_matches.txt', $key . "\t\t" . $value . PHP_EOL, FILE_APPEND); } $secondArray[$key] = $this->_hashesToArray($value); } $thirdArray = []; foreach ($secondArray as $key => $value) { foreach ($value as $key2 => $value2) { if (!$this->_writeToFile) { if (in_array($value2, $this->_expectedString)) { exit( '[' . $this->_inputString . ']=>[' . $key . ']=>[' . $firstArray[$key] . ']=>[' . $key2 . ']=>[' . $value2 . ']' . PHP_EOL ); } } else { file_put_contents('hash_matches.txt', $key . ' => ' . $key2 . "\t\t" . $value2 . PHP_EOL, FILE_APPEND); } $thirdArray[$key][$key2] = $this->_hashesToArray($value2); } } foreach ($thirdArray as $key => $value) { foreach ($value as $key2 => $value2) { foreach ($value2 as $key3 => $value3) { if (!$this->_writeToFile) { if (in_array($value3, $this->_expectedString)) { exit( '[' . $this->_inputString . ']=>[' . $key . ']=>[' . $firstArray[$key] . ']=>[' . $key2 . ']=>[' . $value2 . ']=>[' . $key3 . ']=>[' . $value3 . ']' . PHP_EOL ); } } else { file_put_contents('hash_matches.txt', $key . ' => ' . $key2 . ' => ' . $key3 . "\t\t" . $value3 . PHP_EOL, FILE_APPEND ); } } } } } /** * Return various versions of a input string to hash. * * @param string $string * * @return array */ protected function _hashesToArray($string) { $strings = array( 'input' => $string, 'lower' => strtolower($string), 'lower_reverse' => strtolower(strrev($string)), 'upper_reverse' => strtoupper(strrev($string)), 'upper' => strtoupper($string), 'reverse' => strrev($string), 'reverse_upper' => strrev(strtoupper($string)), 'reverse_lower' => strrev(strtolower($string)), ); $hashTypes = array('md5', 'md4', 'sha1', 'sha256', 'sha512'); $tmpArray = []; foreach ($hashTypes as $hash) { foreach ($strings as $key => $value) { $tmpArray[$hash . '_' . $key] = hash($hash, $value, false); } } foreach ($strings as $key => $value) { $tmpArray['input_' . $key] = $value; $tmpArray['base64_' . $key] = base64_encode($value); $tmpArray['crc32_' . $key] = crc32($value); } return $tmpArray; } } new HashAlgorithms($argv[1], $argv[2], ((isset($argv[3]) && strtolower($argv[3]) === 'true') ? true : false));