Skip to content

Instantly share code, notes, and snippets.

@qikcoin
Last active August 29, 2015 13:58
Show Gist options
  • Save qikcoin/10006050 to your computer and use it in GitHub Desktop.
Save qikcoin/10006050 to your computer and use it in GitHub Desktop.
from:
https://en.bitcoin.it/wiki/Block_hashing_algorithm
<?PHP
function SwapOrder($in){
$Split = str_split(strrev($in));
$x='';
for ($i = 0; $i < count($Split); $i+=2){
$x .= $Split[$i+1].$Split[$i];
}
return $x;
}
$hash='010000008D77';
$h1=base_convert($hash, 16, 2). "\n";
echo $h1;
echo $hash . '<br/>';
$v1 = hex2bin($hash) ;
//echo 'hex2bin($hash): ' . $v1 . "\n";
$v2 = hash('sha256', $v1 );
echo 'hash(sha256, $v1 ): ' .$v2 . "\n";
$v3 = hex2bin( $v2 );
//echo 'hex2bin( $v2 ): ' .$v3 . "\n";
$v4 = hash('sha256',$v3 );
echo 'hash(sha256,$v3 ): ' .$v4 . "\n";
$v5 = SwapOrder($v4);
echo 'SwapOrder: ' .$v5. "\n";
echo "\n"
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment