A few points that folks overlooked in this thread:
1- Iterating from
start to
end requires an addition, i.e. 256 bit addition.
From the programmer's perspective Python handles 256 bits integers trivially but python 2.5+ requires such variable to be defined as
long explicitly, and it is good to know that we are not dealing with a one-cycle operation.
2- It looks that once the production of the output file is finished the journey is just started as OP wants to read this file and produce the corresponding public key for each row, comparing it with his target, so we need multiplication and modulo operations, it raises again performance issues. It is why we should use cryptographically optimized libraries wherever possible.
3-I think, generating a file firstly then feeding it to another python script as input for some computations is not the smartest plan for this use case, especially when we are talking Pythonic
Instead I'd do something like this:
//This is coded for python 2.5+
from pybitcoin import BitcoinPrivateKey
// check the repository here
// https://github.com/blockstack/pybitcoin
start = long(someValueHex)
stop = long( biggerValueHex)
target = long(targetPubKeyHex)
def generate (s,e):
while s <= e:
yield s //it is a generator rather than an ordinary function
s += 1
yield 0
def searchForTarget:
candid = generate(start, stop)
while true:
pk = next(candid)
if pk == 0:
print("Exhausted the search space, sorry, no good news :( " )
break
private_key = BitcoinPrivateKey(pk)
public_key = privatekey.publickey()
if public_key == target:
hex_private_key = private_key.toHex();
print("FOUND! :) /n %s" , %hex_private_key)
break