dimanche 13 septembre 2020

Print () result is not output, can't find error

This script generates a hash, but somewhere it did not correctly write something in the function.

from bitcoin import *
import os
import hashlib
import base58
 

while True:
    priv =  random_key()
    pubkey = privtopub(priv)
    compress_pubkey = False
    
 
    if (compress_pubkey):
        if (ord(pubkey[-2:].decode('hex')) % 2 == 0):
            pubkey_compressed = '02'
        else:
            pubkey_compressed = '03'
        pubkey_compressed += pubkey[2:66]
        hex_str = bytearray.fromhex(pubkey_compressed)
    else:
        hex_str = bytearray.fromhex(pubkey)
 
key_hash = hash160(hex_str)

def hash160(hex_str):
    sha = hashlib.sha256()
    rip = hashlib.new('ripemd160')
    sha.update(hex_str)
    rip.update( sha.digest() )
    print ( "key_hash = \t" + rip.hexdigest() )
    return rip.hexdigest()  # .hexdigest() is hex ASCII

I checked the script to work. Did print (pubkey). The public keys are displayed as a result, but I don't need to get key_hash. Unfortunately when I do print ("key_hash = \ t" + rip.hexdigest ())

The result is not executed! I don't know programming. Help fix the code!




Aucun commentaire:

Enregistrer un commentaire