这个脚本生成了一个散列,但是它没有在函数中正确地写入某些内容
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
我检查了脚本是否正常工作。没有print (pubkey)
。结果将显示公钥,但我不需要获取密钥散列。不幸的是,当我这样做的时候print ("key_hash = \ t" + rip.hexdigest ())
结果没有执行!我不懂编程。帮助修复代码
重新排列代码后:
输出:
注意,有一个无限循环(^ {CD1>}),考虑用特定的迭代次数替换。
相关问题 更多 >
编程相关推荐