Skip to content

Instantly share code, notes, and snippets.

@tzkmx
Created March 6, 2021 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzkmx/028c95dc1986c79d6842bc4cd52a59f0 to your computer and use it in GitHub Desktop.
Save tzkmx/028c95dc1986c79d6842bc4cd52a59f0 to your computer and use it in GitHub Desktop.
experimentos base58
<?php
define('ALPHABET', '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
function numT58($num)
{
$acc = '';
while ($num >= 58) {
$mod = $num % 58;
$num = intval(floor($num / 58));
echo $mod . ' :';
echo ALPHABET[$mod], "\t", $num, "\n";
$acc = ALPHABET[$mod] . $acc;
}
$acc = ALPHABET[$num] . $acc;
echo $acc;
}
function b58dec(string $b58)
{
echo $b58, "\n";
$acc = 0;
$len = $i = strlen($b58);
while ($i-- > 0) {
$char = $b58[$i];
$num = strpos(ALPHABET, $char);
$power = $len - $i - 1;
$up = $num * pow(58, $power);
$acc += $up;
echo json_encode(
compact('i', 'char', 'num',
'power', 'up', 'acc')
), "\n";
}
echo $acc, "\n";
echo dechex($acc);
}
$num1 = 2064940092;
$b58r = '49UMkP';
@tzkmx
Copy link
Author

tzkmx commented Mar 6, 2021

while( true ){ if( strlen($num) < 2 ) { if( intval($num) <= 0 ) { break; } } $rem = bcmod($num, $base); $rep = $basestr[intval($rem)] . $rep; $num = bcdiv(bcsub($num, $rem), $base); } return $rep;

@tzkmx
Copy link
Author

tzkmx commented Mar 10, 2021

sha256(hex): 4569e91f1a2f6e1c3cc085a143e404db91591c2b9c25d1b12c1d88f0bb4c2bad
base58:      5fxoLz932qGvY57xjSq9akM9mp5LaQzjggNxRnWC6dpY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment