Created
April 16, 2020 22:17
-
-
Save Alrighttt/76cbf4df35fc80ab2bb2b72d74c43fba to your computer and use it in GitHub Desktop.
pyCCaddr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import hashlib | |
import binascii | |
import base58 | |
# bitcoin "hash160" ( sha256 + ripemd160 ) | |
def hash160(hexstr): | |
preshabin = binascii.unhexlify(hexstr) | |
my160 = hashlib.sha256(preshabin).hexdigest() | |
return(hashlib.new('ripemd160', binascii.unhexlify(my160)).hexdigest()) | |
def addr_from_ripemd(prefix, ripemd): | |
net_byte = prefix + ripemd | |
bina = binascii.unhexlify(net_byte) | |
sha256a = hashlib.sha256(bina).hexdigest() | |
binb = binascii.unhexlify(sha256a) | |
sha256b = hashlib.sha256(binb).hexdigest() | |
hmmmm = binascii.unhexlify(net_byte + sha256b[:8]) | |
final = base58.b58encode(hmmmm) | |
return(final.decode()) | |
def CCaddr_from_script(script_hexstr): | |
ripemd = hash160(script_hexstr) | |
addr = addr_from_ripemd('3c', ripemd) | |
return addr | |
print(CCaddr_from_script("2ea22c8020e029c511da55523565835887e412e5a0c9b920801b007000df45e545f25028248103120c008203000401cc")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment