Skip to content

Instantly share code, notes, and snippets.

@edvakf
Last active June 30, 2017 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edvakf/159dd9c74078a7b58f228b706f1f40b7 to your computer and use it in GitHub Desktop.
Save edvakf/159dd9c74078a7b58f228b706f1f40b7 to your computer and use it in GitHub Desktop.
collision rate of base64 of md5 split at 7th letter
#!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