LAB 2: Generating Private, Public Keys and Addresses
LAB 2: Generating Private, Public Keys and Addresses
Notice that the public key is larger than the private key. Why?
Part III: Generating a bitcoin address
4. Write the following code:
#import bitcoin
from bitcoin import *
#Generate a private key
my_private_key=random_key()
#display the private key
print("Private Key:%s\n" %my_private_key)
#Generate a public key, derived from private key
my_public_key=privtopub(my_private_key)
#display the public key
print("Public Key:%s\n" %my_public_key)
#Generate a Bitcoin Address
my_bitcoin_address=pubtoaddr(my_public_key)
#display the Bitcoin address
print("Bitcoin Address Key:%s\n" %my_bitcoin_address)
5. Run the code:
NB: Here the Bitcoin address is encoded in Base58 format, not in hexadecimal
format
6. Copy the same public key and pass it through a SHA-256 hash function, then
a RIPEMD-160 function:
Here is my public key:
Public
Key:04c2c95e5975ec319c82e7f64ead574a013396c55f0ff41070d66db902ed87b61e
f62e714bb3eb5488ae139fea6d19f05b36bcfce33a4c63f3dbb73af096c98db3
I am using the following website for hash functions:
https://www.fileformat.info/tool/hash.htm
- SHA-256(public_key)=
265a72a68d9e1fd642526b05c0522cbf418e4435838ac5ffd5e59c2b794cea7e
- RIPEMD-160(SHA-256(public_key))=
f3ecd1b6bb62b2bc29b502946276d8b50cc37d3d
7. Convert your Bitcoin address from Base58Check to Hexadecimal using the
following website: https://www.better-converter.com/Encoders-
Decoders/Base58Check-to-Hexadecimal-Decoder