Personal key used within the instance: a84860187211d36cddfb77fc7638c996b8b8a77d3e16f2e47a5172fe6e8e2be6

Changing Personal Key to WIF (Ruby)


require 'digest'

# Checksums use hash256 (the place information is hashed twice by sha256)
def hash256(hex)
    binary = [hex].pack("H*")
    hash1 = Digest::SHA256.digest(binary)
    hash2 = Digest::SHA256.digest(hash1)
    end result = hash2.unpack("H*")[0]
    return end result
finish

def checksum(hex)
  hash = hash256(hex) # Hash the info by SHA256 twice
  return hash[0...8]  # Return the primary four bytes (eight characters)
finish

def base58_encode(hex)
  @chars = %w[
      1 2 3 4 5 6 7 8 9
    A B C D E F G H   J K L M N   P Q R S T U V W X Y Z
    a b c d e f g h i j k   m n o p q r s t u v w x y z
]
  @base = @chars.size

  i = hex.to_i(16)
  buffer = String.new

  whereas i > 0
    the rest = i % @base
    i = i / @base
    buffer = @chars[remainder] + buffer
  finish

  #! Is it simply the 00, or does 05 get transformed to three, and so on.
  # add '1's to the beginning based mostly on variety of main bytes of zeros
  leading_zero_bytes = (hex.match(/^([0]+)/) ? $1 : '').dimension / 2

  ("1"*leading_zero_bytes) + buffer
finish


# Convert Personal Key to WIF
privatekey = "a84860187211d36cddfb77fc7638c996b8b8a77d3e16f2e47a5172fe6e8e2be6"
prolonged = "80" + privatekey + "01"
extendedchecksum = prolonged + checksum(prolonged)
wif = base58_encode(extendedchecksum)

places wif

Get Public Key from WIF (Python)


from bitcoinutils.setup import setup
from bitcoinutils.keys import PrivateKey, PublicKey

def predominant():
    # setup the community
    setup('mainnet')

    # present WIF key
    priv = PrivateKey.from_wif('L2rq82XD1P9bwnyithBaRYn7v91WxRCSraTrfbu6g86VLYsnCmbt')


    # get the general public key
    pub = priv.get_public_key()

    # compressed public key
    print("Public key:", pub.to_hex(compressed=True))

if __name__ == "__main__":
      predominant()

Supply:

https://github.com/in3rsha/learnmeabitcoin-code/blob/master/keygenerator.rb

https://github.com/karask/python-bitcoin-utils/blob/master/examples/keys_addresses.py

Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here