Last active
June 30, 2017 01:43
-
-
Save edvakf/159dd9c74078a7b58f228b706f1f40b7 to your computer and use it in GitHub Desktop.
collision rate of base64 of md5 split at 7th letter
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 -d memory_limit=10G test.php | |
<?php | |
$a = []; | |
$total = 0; | |
$collision = 0; | |
for ($i = 0; $i < 100000000; $i++) { | |
$total += 1; | |
for ($j = 0; $j < 2; $j++) { | |
$h = substr(base64_encode(md5($j . $i, true)), 0, 7); | |
if (isset($a[$h])) { | |
$collision += 1; | |
continue; | |
} else { | |
$a[$h] = $i; | |
if ($j > 0) { | |
echo $i, "\t", $j, "\t", $total, "\t", $collision, "\t", ($collision / $total), PHP_EOL; | |
} | |
break; | |
} | |
} | |
} | |
//var_export($a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment