3v4l.org

run code in 300+ PHP versions simultaneously
<?php class HashCracker { private $range = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; private $length = 32; private $cycles = 1000; public function runBenchmark($hash, $prefix = '') { foreach ($this->range as $key) { $match = $prefix . $key; $timers[$match] = microtime(true); for ($i = 0; $i < $this->cycles; $i += 1) { // this is where you bomb the server stupidStringComparison($hash, $match); } $timers[$match] = microtime(true) - $timers[$match]; } asort($timers); end($timers); $hit = key($timers); var_dump($hit); if (strlen($hit) >= $this->length) { return $hit; } return $this->runBenchmark($hash, $hit); } } function stupidStringComparison($str1, $str2) { for ($i = 0; $i < strlen($str2) && $i < strlen($str1); $i += 1) { if ($str1[$i] !== $str2[$i]) { return false; } usleep(10); // yes, I can't get something reliable with my box otherwise because of cpu spikes } // really stupid - ignore this part. Just made up to inflate times return strlen($str1) === strlen($str2); } $password = 'hello'; $hashed = md5($password); var_dump('Hash to match: ' . $hashed); $cracked = (new HashCracker())->runBenchmark($hashed); var_dump('Cracked hash: ' . $cracked); var_dump($cracked === $hashed ? 'Success!' : 'Fail :( Retry!');
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7
string(47) "Hash to match: 5d41402abc4b2a76b9719d911017c592" int(5) string(2) "5d"
Process exited with code 137.
Output for 5.3.5 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Tc7XU on line 5
Process exited with code 255.

preferences:
102.52 ms | 401 KiB | 117 Q