Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- import binascii
- def private_key_to_WIF(private_key):
- """Convert the hex private key into Wallet Import Format for easier wallet importing. This function is
- only called if a wallet with a balance is found. Because that event is rare, this function is not significant
- to the main pipeline of the program and is not timed.
- """
- var = hashlib.sha256(binascii.unhexlify(hashlib.sha256(binascii.unhexlify('80' + private_key)).hexdigest())).hexdigest()
- var = binascii.unhexlify('80' + private_key + var[0:8])
- alphabet = chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
- result = ''; value = pad = 0;
- for i, c in enumerate(var[::-1]): value += 256**i * c
- while value >= len(alphabet):
- div, mod = divmod(value, len(alphabet))
- result, value = chars[mod] + result, div
- result = chars[value] + result
- for c in var:
- if c == 0: pad += 1
- else: break
- return chars[0] * pad + result
- print (private_key_to_WIF('ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement