Bitcoin private key: translate from bash to perl

0 votes

I'm working on a Bitcoin brain wallet generator in Perl. I wasn't able to generate the private key (import format).

I have found a very simple bash script to generate the private key, and I will like to have it translated to Perl so I can make the key generation entirely on Perl.

Can someone help me to translate the following bash code to a 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
do echo -n ${base58[n]}
done
Sep 4, 2018 in Blockchain by digger
• 27,620 points
144 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
use bignum; # Get arbitrary precision arithmetic

# base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})
my @base58 = (1 .. 9, 'A' .. 'H', 'J' .. 'N', 'P' .. 'Z', 'a' .. 'k', 'm' .. 'z');
# ibase=16; n=${1^^};
my $n = hex($ARGV[0]);
# while(n>0)
my $result = "";
while ($n > 0) {
  # n%3A, tac, and echo ${base58[n]} (hex 3A == dec 58)
  $result = $base58[$n % 58] . $result;
  # n/=3A
  $n /= 58;
}
print "$result\n";
answered Sep 4, 2018 by slayer
• 29,040 points

Related Questions In Blockchain

0 votes
1 answer

Not able to generate WIF from extended private key

I found the answer to this in the ...READ MORE

answered Aug 29, 2018 in Blockchain by digger
• 27,620 points
38 views
0 votes
1 answer

Is it possible to claim Bitcoin Cash from an exchange that does not support it?

You can't claim BCH without knowing private ...READ MORE

answered Jul 17, 2018 in Blockchain by ariaholic
• 7,320 points
21 views
0 votes
1 answer

How to access bitcoin Daemon from other services?

You don't need all these things to ...READ MORE

answered Aug 29, 2018 in Blockchain by digger
• 27,620 points
106 views
0 votes
1 answer

Is there a way to send funds from a specific bitcoin address in a wallet?

I'll answer my own question, It was unbelievably ...READ MORE

answered Sep 3, 2018 in Blockchain by Perry
• 16,450 points
39 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
42 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
60 views
0 votes
1 answer
0 votes
1 answer

BitcoinJ generate address from private key

Convert string private key into bytes[]: ECKey key = ...READ MORE

answered Sep 4, 2018 in Blockchain by slayer
• 29,040 points
160 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.