Skip to content

Instantly share code, notes, and snippets.

@edvakf edvakf/test.php
Last active Jun 30, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.