Closed wizardofozzie closed 8 years ago
This code works for the json tests, however b58check
functions are now failing.
def changebase(string, frm, to, minlen=0):
if frm == to:
return lpad(string, get_code_string(frm)[0], minlen)
elif frm in (16, 256) and to == 58:
if frm == 16:
nullbytes = re.match('^(00)*', string).group(0)
nblen = len(nullbytes)/2
else:
nullbytes = re.match('^(\x00)*', string).group(0)
nblen = len(nullbytes)
return lpad('', '1', nblen) + encode(decode(string, frm), to)
elif frm == 58 and to in (16, 256):
nullbytes = re.match('^1*', string).group(0)
if to == 16:
padding = lpad('', '00', len(nullbytes))
else:
padding = lpad('', '\x00', len(nullbytes))
return padding + encode(decode(string, frm), to)
return encode(decode(string, frm), to, minlen)
This is necessary just for Base58 check and not for normal Base58 encoding. Please refer to this, point 5 of "Creating a Base58Check string".
@fcracker79 Ahhh, yes, you're right.
Base58 Test vectors failure for 2 test cases:
["00eb15231dfceb60925886b67d065299925915aeb172c06647", "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"]
["00000000000000000000", "1111111111"]
Test Vector 5:
changebase("00eb15231dfceb60925886b67d065299925915aeb172c06647", 16, 58)
returns"NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"
(leading1
missing) The correct result is returned by specifyingminlen=34
, iechangebase("00eb15231dfceb60925886b67d065299925915aeb172c06647", 16, 58, minlen=34)
Test Vector 12:
changebase("00000000000000000000", 16, 58)
returns""
(instead of"1111111111"
). Again, specifiyingminlen=10
fixes this,changebase("00000000000000000000", 16, 58, 10)
.