I have made paper wallets. And I continually send what bitcoins I get to them. I'm paranoid that I've been sending bitcoins to the paper bitcoin addresses where somehow at sometime my saved private keys got corrupted. So from time to time I want to run a script, python or whatever, to check if my private keys do correspond to the public address that I've been sending bitcoins to. I want an offline solution so things like the satoshi client would not do. Is there a small script written by someone that can solve this?
Bitcoin-bash-tools has what you need.
For Python, numtowif() below, from a post by forum user flatfly, does that as well:
import hashlib, binascii t='123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' def numtowif(numpriv): step1 = '80'+hex(numpriv)[2:].strip('L').zfill(64) step2 = hashlib.sha256(binascii.unhexlify(step1)).hexdigest() step3 = hashlib.sha256(binascii.unhexlify(step2)).hexdigest() step4 = int(step1 + step3[:8] , 16) return ''.join([t[step4/(58**l)%58] for l in range(100)])[::-1].lstrip('1') def wiftonum(wifpriv): return sum([t.index(wifpriv[::-1][l])*(58**l) for l in range(len(wifpriv))])/(2**32)%(2**256) def validwif(wifpriv): return numtowif(wiftonum(wifpriv))==wifpriv print numtowif(0x0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) print hex(wiftonum('5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ')) print validwif('5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ') print validwif('5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTK')
Also, Armory client has some C++ that can be compiled and easily accessed from Python which provides this.
I'd check out the python library PyBitcoin (https://github.com/blockstack/pybitcoin or "pip install pybitcoin").
It's pretty simple to get the address from the wif private key:
>>> from pybitcoin import BitcoinPrivateKey >>> private_key = BitcoinPrivateKey() >>> private_key.public_key().address() '1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T'
You can also derive a private key object from it's raw hex representation:
>>> private_key_2 = BitcoinPrivateKey('91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d')
P.S. This library also works with Litecoin, Namecoin and a bunch of other coins.
Disclosure: I'm one of the creators.
Brainwallet.org has quite a lot little useful address tools.
Offhand it looks like
pycoin is more active than
pybitcoin. So I'll put Keir Finlow-Bates' code from a comment above into an answer by itself:
from pycoin.key import Key k = Key.from_text("<yourWIFhere>") k.address()