【发布时间】:2021-08-25 12:29:51
【问题描述】:
朋友们下午好,我刚开始学习python,我发现这段代码适合我的需要,但是在输出的过程中,一切都是同步的,请帮我解决这个问题。 "
import ecdsa
import hashlib
import base58
with open("my_private_key.txt", "r") as f: #Input file path
for line in f:
#Convert hex private key to bytes
private_key = bytes.fromhex(line)
#Derivation of the private key
signing_key = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.SECP256k1)
verifying_key = signing_key.get_verifying_key()
public_key = bytes.fromhex("04") + verifying_key.to_string()
#Hashes of public key
sha256_1 = hashlib.sha256(public_key)
ripemd160 = hashlib.new("ripemd160")
ripemd160.update(sha256_1.digest())
#Adding prefix to identify Network
hashed_public_key = bytes.fromhex("00") + ripemd160.digest()
#Checksum calculation
checksum_full = hashlib.sha256(hashlib.sha256(hashed_public_key).digest()).digest()
checksum = checksum_full[:4]
#Adding checksum to hashpubkey
bin_addr = hashed_public_key + checksum
#Encoding to address
address = str(base58.b58encode(bin_addr))
final_address = address[2:-1]
print(final_address)
with open("my_addresses.txt", "a") as i:
i.write(final_address)
"
【问题讨论】:
-
您好,欢迎@kamburishka,为了让人们正确回答您的问题,我认为如果您能详细说明会有所帮助。当您说“所有内容都在一行中同步”时,您是说很难读取/解释输出,因为它呈现在一大块中?
标签: python bitcoin private-key