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.
Result of php executing
Full code of xor_hash.php
- <?
- function xor_hash($data) {
- $chars = 32; //32 hex chars is 128 bits
- $chunks = str_split(bin2hex($data), $chars);
- $xored = pack('H*', str_repeat('0', $chars));
- foreach ($chunks as $chunk) {
- $xored ^= pack('H*', str_pad($chunk, $chars, '0', STR_PAD_RIGHT));
- }
- return bin2hex($xored);
- }
- $m = "not very long but still pretty long text message";
- echo $m;
- echo "\n";
- echo xor_hash($m);