<s> from . hash import sha256d <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> __b58chars = '<STR_LIT>' <EOL> __b58base = len ( __b58chars ) <EOL> def b58encode ( v ) : <EOL> "<STR_LIT>" <EOL> long_value = <NUM_LIT:0> L <EOL> for ( i , c ) in enumerate ( v [ : : - <NUM_LIT:1> ] ) : <EOL> long_value += ( <NUM_LIT> ** i ) * ord ( c ) <EOL> result = '<STR_LIT>' <EOL> while long_value >= __b58base : <EOL> ( div , mod ) = divmod ( long_value , __b58base ) <EOL> result = __b58chars [ mod ] + result <EOL> long_value = div <EOL> result = __b58chars [ long_value ] + result <EOL> nPad = <NUM_LIT:0> <EOL> for c in v : <EOL> if c == '<STR_LIT>' : <EOL> nPad += <NUM_LIT:1> <EOL> else : <EOL> break <EOL> return ( __b58chars [ <NUM_LIT:0> ] * nPad ) + result <EOL> def b58decode ( v , length = None ) : <EOL> "<STR_LIT>" <EOL> long_value = <NUM_LIT:0> L <EOL> for ( i , c ) in enumerate ( v [ : : - <NUM_LIT:1> ] ) : <EOL> long_value += __b58chars . find ( c ) * ( __b58base ** i ) <EOL> result = '<STR_LIT>' <EOL> while long_value >= <NUM_LIT> : <EOL> ( div , mod ) = divmod ( long_value , <NUM_LIT> ) <EOL> result = chr ( mod ) + result <EOL> long_value = div <EOL> result = chr ( long_value ) + result <EOL> nPad = <NUM_LIT:0> <EOL> for c in v : <EOL> if c == __b58chars [ <NUM_LIT:0> ] : <EOL> nPad += <NUM_LIT:1> <EOL> else : <EOL> break <EOL> result = chr ( <NUM_LIT:0> ) * nPad + result <EOL> if length is not None and len ( result ) != length : <EOL> return None <EOL> return result <EOL> def encode_check ( payload ) : <EOL> '<STR_LIT>' <EOL> checksum = sha256d ( payload ) [ : <NUM_LIT:4> ] <EOL> return b58encode ( payload + checksum ) <EOL> def decode_check ( payload ) : <EOL> '<STR_LIT>' <EOL> payload = b58decode ( payload , None ) <EOL> if payload and sha256d ( payload [ : - <NUM_LIT:4> ] ) [ : <NUM_LIT:4> ] == payload [ - <NUM_LIT:4> : ] : <EOL> return payload [ : - <NUM_LIT:4> ] <EOL> return None </s>
