Post
Topic
Board Development & Technical Discussion
Re: Can someone help with python or SAGE code ?
by
COBRAS
on 03/09/2021, 14:57:05 UTC
What is SAGE?

https://en.wikipedia.org/wiki/SageMath

He is asking for help with some script he made with this programming language.



COBRAS, I'm assuming your code is either not working or doesn't exist at all? I'm inclining more to the second possibility.

I didn't finish this as I have other work to do now, but I'll complete it at a later date.

Code:
# Some python code
# Create compressed public key from points
def point2compressed(x, y):
    if (y % 2 == 0):
        prefix = "02"
    else:
        prefix = "03"
    hx = hex(x)[2:].zfill(64)
    return prefix + hx

# create uncompressed public key from points
def point2uncompressed(x, y):
    hx = hex(x)[2:].zfill(64)
    hy = hex(y)[2:].zfill(64)
    return "04" + hx

#NOTE: code after this line is untested and probably broken

# public key to HASH160
from hashlib import sha256
import bytearray
def hash160(pubkey):
    #TODO This currently doesn't add the required prefix/suffix at the hash.
    hexkey = bytearray.fromhex(pubkey)
    h = sha256()
    h.update(hexkey)
    hash160 = h.digest()
    return hash160
   
#pip install base58
def legacy_address(hash160):
    #TODO

def nested_segwit_address(hash160):
    #TODO

#pip install bech32
def native_segwit_address(hash160):
    #TODO


#pip install requests
import requests
def has_balance(address):
    r = requests.get("https://api.blockchair.com/bitcoin/addresses?address={}".format(address))
    if r.status != 200:
       throw Exception("Got Status {} from Blockchair".format(r.status))
    return r.json()




Bro !!! Thank you very mach for your help. I was temporally basy, so I well come back to my fake base point generator and script some time late.

Regard !!! Wink