keis / base58

Base58 and Base58Check implementation compatible with what is used by the bitcoin network.
MIT License
180 stars 59 forks source link

ValueError: substring not found #28

Closed wilsonehusin closed 6 years ago

wilsonehusin commented 6 years ago

In Python3, b58decode_int function throws the following error:

Traceback (most recent call last):
  File "b58.py", line 13, in <module>
    b = base58.b58decode(m)
  File "/home/wilson/.local/lib/python3.5/site-packages/base58.py", line 83, in b58decode
    acc = b58decode_int(v)
  File "/home/wilson/.local/lib/python3.5/site-packages/base58.py", line 69, in b58decode_int
    decimal = decimal * 58 + alphabet.index(char)
ValueError: substring not found

Line 69 has shifted to line 83 in current repository.

Fixable by replacing .index() with .find()

keis commented 6 years ago

With what input? A character that's not in the alphabet should clearly be an error but maybe with a better message

wilsonehusin commented 6 years ago

It was alphabet, though I forgot exactly. The fact that .find() fixes the issue means the character was part of the alphabet, right? Will update this once I get back to the code.

keis commented 6 years ago

That's the difference between find and index. With index it's an error to not find the needle but find will instead return -1. You can plug this -1 into the calculation but the result will be bogus

wilsonehusin commented 6 years ago

Woops, my bad. Apparently I was attempting to decode hex instead of b58 and 0 raised the error. Sorry for the false alarm!