pybit/Examples/Py2_GetOutputAddress.py
def PK2Addr(pk,
            debug=False):
    """
    PK = public key in hex

    Work in bytes throughout (encode back to hex for any prints)
    """
    # Decode input to binary
    pk = pk.decode("hex")
    if debug:
        print "pk: {0}".format(pk.encode("hex"))

    # Hash SHA256
    h1 = hashlib.sha256(pk).digest()
    if debug:
        print "SHA256: h1: {0}".format(h1.encode("hex"))

    # Hash Ripemd160
    h2 = hashlib.new('ripemd160', h1).digest()
    if debug:
        print "RIPEMD160 h2: {0}".format(h2.encode("hex"))

    # Add version
    addr = b"\00" + h2
    if debug:
        print "version + addr: {0}".format(addr.encode("hex"))

    # Hash SHA256
    h3 = hashlib.sha256(addr).digest()
    if debug:
        print "h3: {0}".format(h3.encode("hex"))

    # Hash SHA256
    h4 = hashlib.sha256(h3).digest()
    if debug:
        print "h4: {0}".format(h4.encode("hex"))

    # Get checksum
    cs = h4[0:4]
    if debug:
        print "checksum: {0}".format(cs.encode("hex"))
        print "h4 + cs: {0}".format((h4 + cs).encode("hex"))

    # Add checksum and convert to base58
    b58 = base58.b58encode(addr + cs)
    if debug:
        print "b58: {0}".format(b58)

    return b58

    PK = public key in hex

    Work in bytes throughout (encode back to hex for any prints)
    
PK = public key in hex
Work in bytes throughout (encode back to hex for any prints)
PK = public key in hex Work in bytes throughout ( encode back to hex for any prints )
def PK2Addr(pk,
            debug=False):
    pk = pk.decode("hex")
    if debug:
        print "pk: {0}".format(pk.encode("hex"))
    h1 = hashlib.sha256(pk).digest()
    if debug:
        print "SHA256: h1: {0}".format(h1.encode("hex"))
    h2 = hashlib.new('ripemd160', h1).digest()
    if debug:
        print "RIPEMD160 h2: {0}".format(h2.encode("hex"))
    addr = b"\00" + h2
    if debug:
        print "version + addr: {0}".format(addr.encode("hex"))
    h3 = hashlib.sha256(addr).digest()
    if debug:
        print "h3: {0}".format(h3.encode("hex"))
    h4 = hashlib.sha256(h3).digest()
    if debug:
        print "h4: {0}".format(h4.encode("hex"))
    cs = h4[0:4]
    if debug:
        print "checksum: {0}".format(cs.encode("hex"))
        print "h4 + cs: {0}".format((h4 + cs).encode("hex"))
    b58 = base58.b58encode(addr + cs)
    if debug:
        print "b58: {0}".format(b58)
    return b58
def PK2Addr ( pk , debug = False ) : pk = pk . decode ( "hex" ) if debug : print "pk: {0}" . format ( pk . encode ( "hex" ) ) h1 = hashlib . sha256 ( pk ) . digest ( ) if debug : print "SHA256: h1: {0}" . format ( h1 . encode ( "hex" ) ) h2 = hashlib . new ( 'ripemd160' , h1 ) . digest ( ) if debug : print "RIPEMD160 h2: {0}" . format ( h2 . encode ( "hex" ) ) addr = b"\00" + h2 if debug : print "version + addr: {0}" . format ( addr . encode ( "hex" ) ) h3 = hashlib . sha256 ( addr ) . digest ( ) if debug : print "h3: {0}" . format ( h3 . encode ( "hex" ) ) h4 = hashlib . sha256 ( h3 ) . digest ( ) if debug : print "h4: {0}" . format ( h4 . encode ( "hex" ) ) cs = h4 [ 0 : 4 ] if debug : print "checksum: {0}" . format ( cs . encode ( "hex" ) ) print "h4 + cs: {0}" . format ( ( h4 + cs ) . encode ( "hex" ) ) b58 = base58 . b58encode ( addr + cs ) if debug : print "b58: {0}" . format ( b58 ) return b58
PK = public key in hex
Work in bytes throughout (encode back to hex for any prints)
PK = public key in hex Work in bytes throughout ( encode back to hex for any prints )
"""
    PK = public key in hex

    Work in bytes throughout (encode back to hex for any prints)
    """ # Decode input to binary # Hash SHA256 # Hash Ripemd160 # Add version # Hash SHA256 # Hash SHA256 # Get checksum # Add checksum and convert to base58
pk
debug