Good job, MelMan2002!
If anyone else is wondering, here's how I replicated the result in PHP:
// adapted from
// http://darklaunch.com/2009/08/07/base58-encode-and-decode-using-php-with-example-base58-encode-base58-decode
function base58_decode($num) {
$alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
$len = strlen($num);
$decoded = 0;
$multi = 1;
for ($i = $len - 1; $i >= 0; $i--) {
$decoded = bcadd($decoded, bcmul($multi, strpos($alphabet, $num[$i])));
$multi = bcmul($multi, strlen($alphabet));
}
return $decoded;
}
function base58_encode($num) {
$alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
$base_count = strlen($alphabet);
$encoded = '';
while (bccomp($num, $base_count) >= 0) {
$div = bcdiv($num, $base_count, 0);
$mod = bcsub($num, bcmul($base_count, $div));
$encoded = $alphabet[$mod] . $encoded;
$num = $div;
}
if ($num) {
$encoded = $alphabet[(int)$num] . $encoded;
}
return $encoded;
}
// http://us2.php.net/manual/en/ref.bc.php#99130
function bcdechex($dec) {
$last = bcmod($dec, 16);
$remain = bcdiv(bcsub($dec, $last), 16);
if($remain == 0) {
return dechex($last);
} else {
return bcdechex($remain).dechex($last);
}
}
$num = base58_decode('3HVMPwe1rr96QryQdZtZt1LWfcXnEFSG9rKiRuv8ewxwvUmZMH1zwn');
$num = bcdiv($num, base58_decode('Xi4'));
$key = bcadd(base58_decode('t'), $num);
echo base58_encode($num), "\n";
echo substr(bcdechex($num), 2, 64), "\n";
(No warranty or anything on this code
)
If I paste the base58 output into the WIF field on
Casascius' address utility, appending "?", it calculates the correct private address and adjusts the WIF to match the correct answer. I'm not sure if this adjustment is because of a bug in my program, or if it's part of the checksum stuff.
The hex goes in fine, although I'll have to read about base58check to see why the substr is necessary.
I'm curious Ean, did you purposely camouflage this to look like base64, even the same length as the last one? If so it seems to have been effective!