Last active
February 1, 2023 10:19
-
-
Save bagart/ce991b0a7c4c85095cdadfbf650ef707 to your computer and use it in GitHub Desktop.
md5_distribution.php
This file contains hidden or 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 | |
declare(strict_types=1); | |
function nulles($max) | |
{ | |
$x = []; | |
for ($i = 1; $i < $max; ++$i) { | |
$md5 = md5((string)$i); | |
$cnt = 0; | |
for ($md_i = 0; $md_i < 32; ++$md_i) { | |
if ($md5[$md_i] !== '0') { | |
break; | |
} | |
++$cnt; | |
} | |
$x[$cnt] = 1 + ($x[$cnt] ?? 0); | |
} | |
return [$max => $x]; | |
} | |
function raspred($x) | |
{ | |
$result = []; | |
foreach ($x as $max => $res) { | |
foreach ($res as $zeros => $count) { | |
$result["от 1 до $max"]["md5 имеет $zeros нулей в начале"] = '1/' . round( | |
$max / $count, | |
3 | |
) . ' или ' . round($count / $max * 100, 2) . '%'; | |
} | |
} | |
return $result; | |
} | |
foreach ( | |
[ | |
5000, | |
10000, | |
50000, | |
100000, | |
500000, | |
1000000, | |
10000000, | |
] as $size | |
) { | |
var_dump(raspred(nulles($size))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
к вопросу о распределении байт в md5
https://habr.com/ru/company/vk/blog/711126/
https://3v4l.org/eRqbS#v8.1.15