matja / bitcoin-tool

Tool for converting Bitcoin keys and addresses
215 stars 118 forks source link

how to use tool as hex-to-base58 conversor? #18

Open ppKrauss opened 7 years ago

ppKrauss commented 7 years ago

I need to convert usual hexadecimal hashes (ex. SHA1 by sha1sum * > sha1sum.txt terminal command) to base58 strings... No bitcoin context... What is the simplest way to do this convesion?


PS: perhaps something as ./bitcoin-tool ... --input-format raw ... --output-format base58check but is not obvius how to obtain a simple and direct conversion.

ruthtern commented 6 years ago

The dc command line calculator will do hex -> base58 conversion Requires $hex in uppercase hex=47CC70C65DEF843F3455B80B157313E096AC5A187F2549356E8DA83300B800BE dc -e "58o16i${hex}p" gives this list of base58 digits -> 04 48 15 43 45 04 29 43 06 43 12 44 37 51 02 43 08 55 46 07 14 39 22\ 13 37 37 13 26 30 19 49 41 44 04 01 57 20 14 30 12 01 49 03 04

To convert these to Bitcoin base58 format, use an array of Bitcoin base58 characters ... b58y=(1 2 3 4 5 6 7 8 9 A B C D E F G H J K L M N P Q R S T U V W X Y Z a b c d e f g h i j k m n o p q r s t u v w x y z) for dgt in $(dc -e "58o16i${hex}p"|tr -d '\\n');do echo -n ${b58y[$((10#$dgt))]};done;echo

5qGkn5Wk7kDmet3k9xo8FgPEeeETXLrim52zMFXD2r45

Or ... hex=47cc70c65def843f3455b80b157313e096ac5a187f2549356e8da83300b800be bitcoin-tool --input-type private-key --input-format hex --output-type private-key --output-format base58 --input $hex --network bitcoin

5qGkn5Wk7kDmet3k9xo8FgPEeeETXLrim52zMFXD2r45