-
-
Save iulianbadoi/d70121c9f1dfccea9aab5ac9182a9695 to your computer and use it in GitHub Desktop.
bitwalletrecover.py - recover compressed private keys from your bitcoin/litecoin/darkcoin wallet. Requires python3, pycoin (https://pypi.python.org/pypi/pycoin), and base58 (https://pypi.python.org/pypi/base58).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## sudo apt-get install python3-setuptools | |
| ## sudo easy_install3 pip | |
| ## | |
| ## sudo pip install pycoin | |
| ## sudo pip install base58 | |
| ## | |
| import re | |
| import hashlib | |
| import base58 | |
| from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent | |
| def bytetohex(byteStr): | |
| return ''.join( [ "%02X" % x for x in byteStr ] ).strip() | |
| litecoin = [b"\x30", b"\xb0"] | |
| bitcoin = [b"\x00", b"\x80"] | |
| darkcoin = [b"\x4c", b"\xcc"] | |
| cointype = darkcoin | |
| walletHandle = open("wallet.dat", "rb") | |
| wallet = walletHandle.read() | |
| privKeys=set(re.findall(b'\x70\x6F\x6F\x6C(.{52})', wallet)) | |
| print("Found %d privKeys" % len(privKeys)) | |
| for key in privKeys: | |
| key = key[20:] | |
| public_x, public_y = public_pair_for_secret_exponent(generator_secp256k1, int(bytetohex(key), 16)) | |
| compressed_public_key = bytes.fromhex("%02x%064x" % (2 + (public_y & 1), public_x)) | |
| #https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses | |
| m = hashlib.new('ripemd160') | |
| m.update(hashlib.sha256(compressed_public_key).digest()) | |
| ripe = m.digest() # Step 2 & 3 | |
| extRipe = cointype[0] + ripe # Step 4 | |
| chksum = hashlib.sha256(hashlib.sha256(extRipe).digest()).digest()[:4] # Step 5-7 | |
| addr = extRipe + chksum # Step 8 | |
| print("Address:", base58.b58encode(addr)) | |
| # compressed wallet import format http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development | |
| key = cointype[1] + key + b"\x01" | |
| chksum = hashlib.sha256(hashlib.sha256(key).digest()).digest()[:4] | |
| addr = key + chksum # Step 8 | |
| print("Private Key:", base58.b58encode(addr),"\n") | |
| walletHandle.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment