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
• 26,740 points
991 views

1 answer to this question.

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,350 points

Related Questions In Blockchain

0 votes
1 answer

How to get Bitcoin Private Key from an ExtPrivKey using NBitcoin

From what I see in the code ...READ MORE

answered Apr 7, 2022 in Blockchain by Aditya
• 7,680 points
982 views
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
• 26,740 points
878 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 aryya
• 7,450 points
526 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
• 26,740 points
1,734 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,116 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
1,636 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,203 views
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,350 points
2,056 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP