fork download
  1. <?php
  2. $cache = [];
  3. $max = pow(2, 16); // 50% chance of collision after 2^16 tries
  4.  
  5. for ($i = 1; $i < $max; $i++) {
  6. $n = rand();
  7. $hashsum = crc32($n);
  8.  
  9. if (isset($cache[$hashsum])) {
  10. print "Collision: crc32($n) == crc32({$cache[$hashsum]}) == $hashsum\n";
  11. } else {
  12. $cache[$hashsum] = $n;
  13. }
  14. }
Success #stdin #stdout 0.11s 20520KB
stdin
Standard input is empty
stdout
Collision: crc32(518228525) == crc32(518228525) == 1860895682
Collision: crc32(1742686287) == crc32(1759063032) == 242179351