Simple translation from bash to perl - Bitcoin private key import format -
i'm working on bitcoin brain wallet generator in perl. wasn't able make last step correctly (base58 encode) generate private key (import format).
i have found simple bash script job, , have translated perl can make key generation entirely on perl.
can me translate following bash code perl sub?
#!/bin/bash base58=({1..9} {a..h} {j..n} {p..z} {a..k} {m..z}) bc <<<"ibase=16; n=${1^^}; while(n>0) { n%3a ; n/=3a }" | tac | while read n echo -n ${base58[n]} done
edit: thank barmar! it's closer, not working. did closest result was:
sub encode_base58sp { $in = shift; $out = ''; @base58 = (1 .. 9, 'a' .. 'h', 'j' .. 'n', 'p' .. 'z', 'a' .. 'k', 'm' .. 'z'); $n = hex($in); while ($n > 1) { $remain = $n % 58; $out = $base58[$remain] . $out; $n /= 58; } return $out; }
with first 9 chars okay, rest wrong... idea?
use bignum; # arbitrary precision arithmetic # base58=({1..9} {a..h} {j..n} {p..z} {a..k} {m..z}) @base58 = (1 .. 9, 'a' .. 'h', 'j' .. 'n', 'p' .. 'z', 'a' .. 'k', 'm' .. 'z'); # ibase=16; n=${1^^}; $n = hex($argv[0]); # while(n>0) $result = ""; while ($n > 0) { # n%3a, tac, , echo ${base58[n]} (hex 3a == dec 58) $result = $base58[$n % 58] . $result; # n/=3a $n /= 58; } print "$result\n";
Comments
Post a Comment