snippetpythonMinor
Generate a Bitcoin Address and the Wif from a phrase
Viewed 0 times
fromtheaddressgeneratephraseandbitcoinwif
Problem
Is there a way to speed up my Python code?
To try it you need to install these libraries:
This program generates a Bitcoin Address and the Wif from a phrase, but the problem is that it generates the Output in about 1 second, and that's too long. So i'm looking for a way to speed it up, and if there aren't any solutions, perhaps I could use another programming language?
Thank you.
import scrypt
import binascii
from passlib.utils.pbkdf2 import get_prf, pbkdf2
from coinkit import BitcoinKeypair
def getWallet(phrase, saltPhrase):
s1 = scrypt.hash(password=phrase+'\x01', salt=saltPhrase+'\x01', N=1<<18, r=8, p=1, buflen=32)
s2 = pbkdf2(phrase+'\x02', saltPhrase+'\x02', 1<<16, keylen=32, prf='hmac-sha256')
key = ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2))
key_hex = binascii.hexlify(key)
newWallet = BitcoinKeypair(key_hex)
return {"walletAddress":newWallet.address(), "walletWif":newWallet.wif_pk()}
myWallet = getWallet("ER8FT+HFjk0", "a@b.c")
print "Address: "+myWallet["walletAddress"]+"\nWif: "+myWallet["walletWif"]To try it you need to install these libraries:
pip install scrypt passlib coinkitThis program generates a Bitcoin Address and the Wif from a phrase, but the problem is that it generates the Output in about 1 second, and that's too long. So i'm looking for a way to speed it up, and if there aren't any solutions, perhaps I could use another programming language?
Thank you.
Solution
If you're planning on running this repeatedly, you could try running this on PyPy, and see if the JIT starts to speed up some of the regions being run repeatedly. That would be a low-effort way to try to get a performance improvement on long-running code.
Before doing any code changes, profile your current code. That should tell you where the most gains are to be had. Then you could move forward with optimizing with a lot more information.
And, it's possible that doing this in a language with a really good compiler for native machine code would get you faster results. I would tend to think of OCaML in that context, but your milage may vary.
Before doing any code changes, profile your current code. That should tell you where the most gains are to be had. Then you could move forward with optimizing with a lot more information.
And, it's possible that doing this in a language with a really good compiler for native machine code would get you faster results. I would tend to think of OCaML in that context, but your milage may vary.
Context
StackExchange Code Review Q#157433, answer score: 2
Revisions (0)
No revisions yet.