Created
May 29, 2014 10:10
-
-
Save natmchugh/d9d4cd3118e4916b931e to your computer and use it in GitHub Desktop.
Quick check of the table at http://en.wikipedia.org/wiki/Birthday_attack
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 | |
$hashes = []; | |
$count = 0; | |
while (true) { | |
$randBytes = openssl_random_pseudo_bytes(100); | |
++$count; | |
$hash = hash('md5', $randBytes); | |
$smallerHash = substr($hash, 0, 8); | |
if (isset($hashes[$smallerHash])) { | |
$collision = base64_encode($hashes[$smallerHash]); | |
printf("Collision found after %s, %s and %s both hash to %s", $count, $collision, base64_encode($randBytes), $smallerHash); | |
echo PHP_EOL; | |
break; | |
} | |
$hashes[$smallerHash] = $randBytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment