Y
Y
YourQuestion2016-06-10 13:30:43
PHP
YourQuestion, 2016-06-10 13:30:43

Can the last 3 characters of md5 be repeated?

Good afternoon.

$sol = 'MMMddFF';
echo md5(time().$sol);

The question is - can the last 3 characters from the hash be repeated, and if so, how to find out after what time the next match of the current 3 characters will be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2016-06-10
@alsopub

$start = time();
$count = 100000;
$sol = 'MMMddFF';


$last = $start;
$s = substr(md5($start.$sol), 32-3);
echo('Last: '.$s.' at '.$start);
for ($i=$start+1; $i<$start+$count; $i++) {
  $cs = substr(md5($i.$sol), 32-3);
  if ($s == $cs) {
    echo(', '.$i.' ('.($i-$last).')');
    $last = $i;
  }
}

Output (it will be different each time you run it):
The frequency of repetitions can be estimated.
The number of combinations of 3 characters md5 - 16^3 = 4096, which is on average every 4096 units will be repeated.
I repeat - on average, no guarantee.
Each character md5 is 0...9 + a...f total 16 options.
Combinations of three such symbols - 16 to the power of 3 - are the basics of combinatorics.
That is, we have a total of 4096 possible md5 endings.
md5() yields a statistically unpredictable (read random) value on average.
So the chance to get the given one sequentially is 1/4096, which gives a repetition through (on average) 4096.
PS. In this case, it does not matter where to get these 3 characters from - from the end, from the beginning, from the middle, even from an arbitrary place each time, and even if these three characters are taken from different random positions - the result is the same - 4096 options, pseudo-random distribution, repetition an average of 4096.

A
Alexey Skobkin, 2016-06-10
@skobkin

What's the difference if it's md5 or something else? You take only 3 characters. That's a total of 16 ( [a-f0-9]) different meanings for each character.
16^3 = 4096.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question