Advertisement
skip420

BTC_Wif

Jun 2nd, 2019
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import hashlib
  2. import binascii
  3.  
  4. def private_key_to_WIF(private_key):
  5.     """Convert the hex private key into Wallet Import Format for easier wallet importing. This function is
  6.    only called if a wallet with a balance is found. Because that event is rare, this function is not significant
  7.    to the main pipeline of the program and is not timed.
  8.    """
  9.     var = hashlib.sha256(binascii.unhexlify(hashlib.sha256(binascii.unhexlify('80' + private_key)).hexdigest())).hexdigest()
  10.     var = binascii.unhexlify('80' + private_key + var[0:8])
  11.     alphabet = chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
  12.     result = ''; value = pad = 0;
  13.     for i, c in enumerate(var[::-1]): value += 256**i * c
  14.     while value >= len(alphabet):
  15.         div, mod = divmod(value, len(alphabet))
  16.         result, value = chars[mod] + result, div
  17.     result = chars[value] + result
  18.     for c in var:
  19.         if c == 0: pad += 1
  20.         else: break
  21.     return chars[0] * pad + result
  22.  
  23. print (private_key_to_WIF('ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement