pybit/Examples/Py2_GetOutputAddress.py
def P2PKH(pk,
          debug=True):
    """
    PK = public key in hex
    """
    # Decode input to binary
    pk = pk.decode("hex")
    if debug:
        print "pk_op: {0}".format(pk.encode("hex"))

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

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

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

    # Add first 4 bytes of second hash to pk (already hex)
    pk = pk + h2[0:4]
    if debug:
        print "pk + checksum: {0}".format(pk.encode("hex"))

    # Convert to base 58 (bin -> base58)
    b58 = base58.b58encode(pk)
    if debug:
        print "b58: {0}".format(b58)

    return b58

    PK = public key in hex
    
PK = public key in hex
PK = public key in hex
def P2PKH(pk,
          debug=True):
    pk = pk.decode("hex")
    if debug:
        print "pk_op: {0}".format(pk.encode("hex"))
    pk = b"\00" + pk
    if debug:
        print "pk + ver: {0}".format(pk.encode("hex"))
    h1 = hashlib.sha256(pk).digest()
    if debug:
        print "h1: {0}".format(h1.encode("hex"))
     again
    h2 = hashlib.sha256(h1).digest()
    if debug:
        print "h2: {0}".format(h2.encode("hex"))
    pk = pk + h2[0:4]
    if debug:
        print "pk + checksum: {0}".format(pk.encode("hex"))
    b58 = base58.b58encode(pk)
    if debug:
        print "b58: {0}".format(b58)
    return b58
def P2PKH ( pk , debug = True ) : pk = pk . decode ( "hex" ) if debug : print "pk_op: {0}" . format ( pk . encode ( "hex" ) ) pk = b"\00" + pk if debug : print "pk + ver: {0}" . format ( pk . encode ( "hex" ) ) h1 = hashlib . sha256 ( pk ) . digest ( ) if debug : print "h1: {0}" . format ( h1 . encode ( "hex" ) ) h2 = hashlib . sha256 ( h1 ) . digest ( ) if debug : print "h2: {0}" . format ( h2 . encode ( "hex" ) ) pk = pk + h2 [ 0 : 4 ] if debug : print "pk + checksum: {0}" . format ( pk . encode ( "hex" ) ) b58 = base58 . b58encode ( pk ) if debug : print "b58: {0}" . format ( b58 ) return b58
PK = public key in hex
PK = public key in hex
"""
    PK = public key in hex
    """ # Decode input to binary # Add version # Hash # Hash again # Add first 4 bytes of second hash to pk (already hex) # Convert to base 58 (bin -> base58)
pk
debug