xor_hash - 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.php

  1. <?
  2.  
  3. function xor_hash($data) {
  4.     $chunks = str_split(bin2hex($data), 32); //128 bits is 32 hex chars
  5.     $xored = pack('H*', str_repeat('0', 32));
  6.     foreach ($chunks as $chunk) {
  7.         $xored ^= pack('H*', $chunk);
  8.     }
  9.     return str_pad(bin2hex($xored), 32, '0', STR_PAD_LEFT);
  10. }
  11.  
  12. $m = "not very long but still pretty long test message";
  13. echo $m;
  14. echo "\n";
  15. echo xor_hash($m);
File Description
  • xor_hash
  • PHP Code
  • 27 Sep-2020
  • 385 Bytes
You can Share it: