xor_hash collision - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of xor_hash collision.php

  1. <?
  2.  
  3. function xor_hash($data) {
  4.     $chars = 32; //32 hex chars is 128 bits
  5.     $chunks = str_split(bin2hex($data), $chars);
  6.     $xored = pack('H*', str_repeat('0', $chars));
  7.     foreach ($chunks as $chunk) {
  8.         $xored ^= pack('H*', str_pad($chunk, $chars, '0', STR_PAD_RIGHT));
  9.     }
  10.     return bin2hex($xored);
  11. }
  12.  
  13. //     0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
  14. //     11111111111111112222222222222222333333333333333344444444444444445555555555555555
  15. $m1 = "The result is player A will     win             player B will   lose            ";
  16. $m2 = "The result is player A will     lose            player B will   win             ";
  17.  
  18. echo $m1;
  19. echo "<br>";
  20. echo xor_hash($m1);
  21. echo "<br>";
  22. echo $m2;
  23. echo "<br>";
  24. echo xor_hash($m2);
File Description
  • xor_hash collision
  • PHP Code
  • 27 Sep-2020
  • 775 Bytes
You can Share it: