0

I find lots of tools/scripts written in python which can generate random number then using this random number it generates Bitcoin Private key(WIF) -> Bitcoin Address pair.

I have tried verifying few pairs using www.bitaddress.org >> Wallet Details by entering WIF key and verifying with output address.

But How can one make sure, the tools/scripts will always generate valid address and key pair ?

or is this like this way

if it generates one valid address and key pair it means all the future address and key pairs will be valid ?

i was looking at this https://github.com/shirriff/bitcoin-code

from makeAddr.py

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

i know random number/string generated using this method is not very much secure, but i am talking in terms of valid WIF and address pair.

  • Read the rfc's and write your own is only real way. There could be bugs? But outside of that this is good question. I think bitcoin.org recommends some. – marshal craft Aug 19 '17 at 4:03
1

you need to make sure that the private is lower than 1.158 * 10^77 (115792089237316195423570985008687907852837564279074904382605163141518161494337) and

In your case you could do

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

 from ecdsa.curves import SECP256k1
 decoded_private_key = int(private_key,16)
 if decoded_private_key > 0 and  decoded_private_key < SECP256k1.generator.order():
     print 'valid'
 else:
     print 'invalid'
| improve this answer | |
  • File "mycode\bitcoin-code-master\makeAddr.py", line 8, in <module> if decoded_private_key > 0 and decode_private_key < SECP256k1.generator.order(): NameError: name 'decode_private_key' is not defined – user10603 Aug 19 '17 at 4:08
  • dang, idk how i too missed that. – user10603 Aug 19 '17 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy