Well, I have a little problem implementing Blake Hash in my server because it is not a x64 server machine. I made a little function that use the powerfull of BC library to do the bitwise operation Shift.
<?php
echo 'Left Shift test<br />';
bprint('1', decbin(1));
bprint('1 << 32 (Fail)', decbin(1 << 32)); bprint('shiftleft(1, 32) (Success)', dec2bin(shiftleft('1', '32'))); echo '<br />';
echo 'Right Shift test<br />';
bprint('9223372036854775808', dec2bin('9223372036854775808'));
bprint('9223372036854775808 >> 63 (Fail)', decbin(9223372036854775808 >> 63));
bprint('rightshift(9223372036854775808, 63) (Success)', decbin(rightshift('9223372036854775808', '63')));
function shiftleft($num, $bits) {
return bcmul($num, bcpow('2', $bits));
}
function rightshift($num, $bits) {
return bcdiv($num, bcpow('2', $bits));
}
function bprint($title, $content) {
echo $title . '<br />' . str_pad($content, 64, '0', STR_PAD_LEFT) . '<br />' . PHP_EOL;
}
function dec2bin($dec) {
for ($b = '', $r = $dec; $r >1;) {
$n = floor($r / 2);
$b = ($r - $n * 2) . $b;
$r = $n; }
return ($r % 2) . $b;
}
?>