fork(4) download
  1. <?php
  2.  
  3. // step 1
  4.  
  5. $publickey='0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6';
  6.  
  7. $step1=hexStringToByteString($publickey);
  8.  
  9. echo "step1 ".$publickey."<br>";
  10.  
  11. // step 2
  12.  
  13. $step2=hash("sha256",$step1);
  14. echo "step2 ".$step2."<br>";
  15.  
  16. // step 3
  17.  
  18. $step3=hash('ripemd160',hexStringToByteString($step2));
  19. echo "step3 ".$step3."<br>";
  20.  
  21. // step 4
  22.  
  23. $step4="00".$step3;
  24. echo "step4 ".$step4."<br>";
  25.  
  26. // step 5
  27.  
  28. $step5=hash("sha256",hexStringToByteString($step4));
  29. echo "step5 ".$step5."<br>";
  30.  
  31. // step 6
  32.  
  33. $step6=hash("sha256",hexStringToByteString($step5));
  34. echo "step6 ".$step6."<br>";
  35.  
  36. // step 7
  37.  
  38. $checksum=substr($step6,0,8);
  39. echo "step7 ".$checksum."<br>";
  40.  
  41. // step 8
  42.  
  43. $step8=$step4.$checksum;
  44. echo "step8 ".$step8."<br>";
  45.  
  46. // step 9
  47. // base conversion is from hex to base58 via decimal.
  48. // Leading hex zero converts to 1 in base58 but it is dropped
  49. // in the intermediate decimal stage. Simply added back manually.
  50.  
  51. $step9="1".bc_base58_encode(bc_hexdec($step8));
  52. echo "step9 ".$step9."<br><br>";
  53.  
  54.  
  55. function hexStringToByteString($hexString){
  56. $len=strlen($hexString);
  57.  
  58. $byteString="";
  59. for ($i=0;$i<$len;$i=$i+2){
  60. $charnum=hexdec(substr($hexString,$i,2));
  61. $byteString.=chr($charnum);
  62. }
  63.  
  64. return $byteString;
  65. }
  66.  
  67. // BCmath version for huge numbers
  68. function bc_arb_encode($num, $basestr) {
  69. if( ! function_exists('bcadd') ) {
  70. Throw new Exception('You need the BCmath extension.');
  71. }
  72.  
  73. $base = strlen($basestr);
  74. $rep = '';
  75.  
  76. while( true ){
  77. if( strlen($num) < 2 ) {
  78. if( intval($num) <= 0 ) {
  79. break;
  80. }
  81. }
  82. $rem = bcmod($num, $base);
  83. $rep = $basestr[intval($rem)] . $rep;
  84. $num = bcdiv(bcsub($num, $rem), $base);
  85. }
  86. return $rep;
  87. }
  88.  
  89. function bc_arb_decode($num, $basestr) {
  90. if( ! function_exists('bcadd') ) {
  91. Throw new Exception('You need the BCmath extension.');
  92. }
  93.  
  94. $base = strlen($basestr);
  95. $dec = '0';
  96.  
  97. $num_arr = str_split((string)$num);
  98. $cnt = strlen($num);
  99. for($i=0; $i < $cnt; $i++) {
  100. $pos = strpos($basestr, $num_arr[$i]);
  101. if( $pos === false ) {
  102. Throw new Exception(sprintf('Unknown character %s at offset %d', $num_arr[$i], $i));
  103. }
  104. $dec = bcadd(bcmul($dec, $base), $pos);
  105. }
  106. return $dec;
  107. }
  108.  
  109.  
  110. // base 58 alias
  111. function bc_base58_encode($num) {
  112. return bc_arb_encode($num, '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
  113. }
  114. function bc_base58_decode($num) {
  115. return bc_arb_decode($num, '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
  116. }
  117.  
  118. //hexdec with BCmath
  119. function bc_hexdec($num) {
  120. return bc_arb_decode(strtolower($num), '0123456789abcdef');
  121. }
  122. function bc_dechex($num) {
  123. return bc_arb_encode($num, '0123456789abcdef');
  124. }
  125. ?>
Success #stdin #stdout 0.04s 52480KB
stdin
Standard input is empty
stdout
step1 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6<br>step2 600ffe422b4e00731a59557a5cca46cc183944191006324a447bdb2d98d4b408<br>step3 010966776006953d5567439e5e39f86a0d273bee<br>step4 00010966776006953d5567439e5e39f86a0d273bee<br>step5 445c7a8007a93d8733188288bb320a8fe2debd2ae1b47f0f50bc10bae845c094<br>step6 d61967f63c7dd183914a4ae452c9f6ad5d462ce3d277798075b107615c1a8a30<br>step7 d61967f6<br>step8 00010966776006953d5567439e5e39f86a0d273beed61967f6<br>step9 16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM<br><br>