0% found this document useful (1 vote)
911 views1 page

Tex BTC

This Python script contains functions for generating and converting Bitcoin private and public keys, addresses, and WIF formats. It uses the ECDSA library to generate public keys from private keys. Addresses are generated by hashing the public key with SHA256 and RIPEMD160 then adding a checksum. Private keys, public keys, and addresses can all be converted between common Bitcoin formats. The script demonstrates generating a random private key and printing the related public key, WIF, and address.

Uploaded by

LAYYAH TIMES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
911 views1 page

Tex BTC

This Python script contains functions for generating and converting Bitcoin private and public keys, addresses, and WIF formats. It uses the ECDSA library to generate public keys from private keys. Addresses are generated by hashing the public key with SHA256 and RIPEMD160 then adding a checksum. Private keys, public keys, and addresses can all be converted between common Bitcoin formats. The script demonstrates generating a random private key and printing the related public key, WIF, and address.

Uploaded by

LAYYAH TIMES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import ecdsa

import random
import hashlib

b58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

def privateKeyToWif(key_hex):
return base58CheckEncode(0x80, key_hex.decode('hex'))

def privateKeyToPublicKey(s):
sk = ecdsa.SigningKey.from_string(s.decode('hex'), curve=ecdsa.SECP256k1)
vk = sk.verifying_key
return ('\04' + sk.verifying_key.to_string()).encode('hex')

def pubKeyToAddr(s):
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
return base58CheckEncode(0,ripemd160.digest())

def keyToAddr(s):
return pubKeyToAddr(privateKeyToPublicKey(s))

def base58encode(n):
result = ''
while n > 0:
result = b58[n%58] + result
n /= 58
return result

def base58CheckEncode(version, payload):


s = chr(version) + payload
checksum = hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4]
result = s + checksum
leadingZeros = countLeadingChars(result, '\0')

return '1' * leadingZeros + base58encode(base256decode(result))

def base256decode(s):
result = 0
for c in s:
result = result * 256 + ord(c)
return result

def countLeadingChars(s, ch):


count = 0
for c in s:
if c == ch:
count += 1
else:
break
return count

private_key = ''.join(['%x' % random.randrange(16) for x in range(0, 64)])


print 'Private key: ',private_key
pubKey = privateKeyToPublicKey(private_key)
print '\nPublic key: ',pubKey
print '\nWif: ',privateKeyToWif(private_key)
print '\nAddress: ',keyToAddr(private_key)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy