1

I am using the conversion algorithm of http://lenschulwitz.com/base58 , this perl code.

  • MANY GOOD CONVERSIONS, AS: 18e559fc6cb0e8de2ce8b50007d474a0d886208e698a07948671e0df520c1525 was converted to 2gBdDRXoLPEhgf9Zd7zw5ujK1qcoPZoendBQJ22VjgqS, all 44 digits.

  • BAD CONVERSION: 0ab3de5e16675aeb0c4831f5218901fec56f39cc8ad16e5559be4a0ee211f5d0 was converted to in9v3fi1cntD6ERD6QryMJq4r5BncjYZ32xZA6Uj4ST, 43 digits!

  • other BAD: 00000000000000000000000000000000000000000000000000000000000000d0 to 11111111111111111111111111111114b

What is wrong with the Perl code? I can use some kind of padding in base58-btc?


PS: I can use something as sudo apt-get install libbase58-0 that is reliable at UBUNTU... But need a Perl interface for it.

Peter Krauss
  • 13,174
  • 24
  • 167
  • 304

2 Answers2

0

Rather than debugging that poorly laid-out code, I suggest that you install Encode::Base58 or Encode::Base58::GMP

Both of those modules have maintainers who will answer questions if you find you are getting incorrect results

Borodin
  • 126,100
  • 9
  • 70
  • 144
0

Tested with other conversors, as bs58 js lib, all producing same and consistent results.

It seems XY problem... perhaps the real question is "base58 bitcoin use fixed size representation?" Can I use something as pad 1s?

But it is also part of the answer, not edited the question (reverted) and proced an answer.


... It is a conversion between "incompatible" bases (!), so I think is impossible ... 58=2*29 is not a multiple of 16=2^4... only when digits are multiple of 2... But:

  • base50("E") = hex("0D"); base58("1E") = hex("000D"); ... the number of padding digits are converted as multiple...

  • what the problem of cut/add for padding? base50("E") = hex("D"); base58("1E") = hex("D"); base50("E")=hex("000000D"); base50("1111111111E")=hex("D"); ... Not seems a problem, so padding-algorithm (fill 0s or 1s) can be used.

SOLUTION: ok, lets pad, fill 1s when converted have less than 44 digits.

Community
  • 1
  • 1
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304