Uniform distribution of truncated md5?

后端 未结 2 1060
小鲜肉
小鲜肉 2020-12-25 10:29

Can we say that a truncated md5 hash is still uniformly distributed?

To avoid misinterpretations: I\'m aware the chance of collisions is much greater th

2条回答
  •  失恋的感觉
    2020-12-25 11:32

    I wrote a little php-program to answer this question. It's not very scientific, but it shows the distribution for the first and the last 8 bits of the hashvalues using the natural numbers as hashtext. After about 40.000.000 hashes the difference between the highest and the lowest counts goes down to 1%, so I'd say the distribution is ok. I hope the code is more precise in explaining what was computed :-) Btw, with a similar program I found that the last 8 bits seem to be distributed slightly better than the first.

     $max) $max = $n;
          print $n."\t";
        }
        print "\n";
      }
      print "Hashes: $hashCount, Min: $min, Max: $max, Delta: ".((($max-$min)*100)/$max)."%\n";
    } 
    ?>
    

提交回复
热议问题