Pages:
Author

Topic: Python snippet to create Bitcoin public/private key pairs - page 2. (Read 3829 times)

legendary
Activity: 1456
Merit: 1083
I may write code in exchange for bitcoins.
There are a few more steps to go from a public-key to a bitcoin address, you have to do some hashing, append a checksum, then finally convert to bitcoin base58.  The details you want are here: https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

I run a test and it gives me the key in the following format. Seed number was 10000000000000000000.

Private:
8ac7230489e80000

Public:
041330daea0d10ec59a9f65dedd79651fad3388a2f16738678c2a1c67077038dab0e909efa28690 12fc532b4552ae7400c8760113b2fcc6f76b71a7077d43a5f9f


How can I get the format 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm (public key) and 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf (private key) ?

I am looking for a Python snippet to create public/private key pairs for Bitcoin just by providing an arbitrary number between 1 and 10^77. Can someone provide such a snippet?

Try this:
Quote
from ecdsa.ecdsa import *
from binascii import hexlify

def getKeys(secretNumber):
  pubKey = Public_key(generator_secp256k1,generator_secp256k1*secretNumber)
  formattedPubKey = hexlify('\x04'+int_to_string(pubKey.point.x())+int_to_string(pubKey.point.y()))
  formattedPrivKey = hex(secretNumber)[2:-1]
  return (formattedPrivKey, formattedPubKey)


If you don't have python-ecdsa installed, you can
get it here: https://github.com/warner/python-ecdsa
tyz
legendary
Activity: 3360
Merit: 1533
I run a test and it gives me the key in the following format. Seed number was 10000000000000000000.

Private:
8ac7230489e80000

Public:
041330daea0d10ec59a9f65dedd79651fad3388a2f16738678c2a1c67077038dab0e909efa28690 12fc532b4552ae7400c8760113b2fcc6f76b71a7077d43a5f9f


How can I get the format 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm (public key) and 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf (private key) ?

I am looking for a Python snippet to create public/private key pairs for Bitcoin just by providing an arbitrary number between 1 and 10^77. Can someone provide such a snippet?

Try this:
Quote
from ecdsa.ecdsa import *
from binascii import hexlify

def getKeys(secretNumber):
  pubKey = Public_key(generator_secp256k1,generator_secp256k1*secretNumber)
  formattedPubKey = hexlify('\x04'+int_to_string(pubKey.point.x())+int_to_string(pubKey.point.y()))
  formattedPrivKey = hex(secretNumber)[2:-1]
  return (formattedPrivKey, formattedPubKey)


If you don't have python-ecdsa installed, you can
get it here: https://github.com/warner/python-ecdsa
newbie
Activity: 7
Merit: 0
I am looking for a Python snippet to create public/private key pairs for Bitcoin just by providing an arbitrary number between 1 and 10^77. Can someone provide such a snippet?

Try this:
Quote
from ecdsa.ecdsa import *
from binascii import hexlify

def getKeys(secretNumber):
  pubKey = Public_key(generator_secp256k1,generator_secp256k1*secretNumber)
  formattedPubKey = hexlify('\x04'+int_to_string(pubKey.point.x())+int_to_string(pubKey.point.y()))
  formattedPrivKey = hex(secretNumber)[2:-1]
  return (formattedPrivKey, formattedPubKey)


If you don't have python-ecdsa installed, you can
get it here: https://github.com/warner/python-ecdsa
legendary
Activity: 1456
Merit: 1083
I may write code in exchange for bitcoins.
Thanks for sharing!
It took me some time to extract the right code lines but I got it.
It's not the best solution but it does it's job Smiley


I don't have the snippet for you ready-made, but I'd take a look in the pycoin library, specifically the Key class:

https://github.com/richardkiss/pycoin
https://github.com/richardkiss/pycoin/blob/master/pycoin/key/Key.py

The Key class has several methods which do something pretty close to what you want.  Specifically, check out the Key.from_text(text) method and the subroutines in there.  I think you'll find it helpful (I hope).

No problem, out of curiosity, which lines did you end up extracting and why did you find it less than optimal?
tyz
legendary
Activity: 3360
Merit: 1533
Thanks for sharing!
It took me some time to extract the right code lines but I got it.
It's not the best solution but it does it's job Smiley

I don't have the snippet for you ready-made, but I'd take a look in the pycoin library, specifically the Key class:

https://github.com/richardkiss/pycoin
https://github.com/richardkiss/pycoin/blob/master/pycoin/key/Key.py

The Key class has several methods which do something pretty close to what you want.  Specifically, check out the Key.from_text(text) method and the subroutines in there.  I think you'll find it helpful (I hope).
legendary
Activity: 1456
Merit: 1083
I may write code in exchange for bitcoins.
I don't have the snippet for you ready-made, but I'd take a look in the pycoin library, specifically the Key class:

https://github.com/richardkiss/pycoin
https://github.com/richardkiss/pycoin/blob/master/pycoin/key/Key.py

The Key class has several methods which do something pretty close to what you want.  Specifically, check out the Key.from_text(text) method and the subroutines in there.  I think you'll find it helpful (I hope).
tyz
legendary
Activity: 3360
Merit: 1533
I am looking for a Python snippet to create public/private key pairs for Bitcoin just by providing an arbitrary number between 1 and 10^77. Can someone provide such a snippet?
Pages:
Jump to: