Basically, I was searching through my drive and old files, and forgot about this tool, not sure if its a working version or not.
Might be useful to others that are digging through their old files. I used this about a year ago and found 300,000 dogecoins and 0.3 Bitcoins.
I combined several codes together and came up with a utility a year ago or so. The prompt: "Gather Keys or Check Keys"
Might be useful, for users digging up wallet.dat files, or searching files back from 2010,2011, etc. I have attached both the source code, and the executable file. KeyExtractor.rar - "PrivateKey.exe" -
https://filebin.net/peiyfi092vs1m6w01)
![](https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2FYMLdrZz.png&t=665&c=RJRi9_QXW7bbcQ)
2)
![](https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2FHcvncYQ.png&t=665&c=G4_ebwnXlV9Xlg)
3)
![](https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2FsgACvbE.png&t=665&c=_iA9gKoj6OKyLw)
4)
![](https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2FxkuVCc6.png&t=665&c=zHrZIxHhrN3nIA)
Executable File:
import re
import hashlib
import base58
import binascii
import argparse
import glob
import fileinput
import argparse
import requests
import pycoin
from time import sleep
from pycoin.key.Key import Key
from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent
mode = input('(gather) keys or (check) balanaces: ')
location = input('Location of .dat files or keylist: ')
coinname = input('BTC, LTC, DOGE, or DASH: ').upper()
def from_long(v, prefix, base, charset):
l = bytearray()
while v > 0:
try:
v, mod = divmod(v, base)
l.append(charset(mod))
except Exception:
raise EncodingError("can't convert to character corresponding to %d" % mod)
l.extend([charset(0)] * prefix)
l.reverse()
return bytes(l)
def to_bytes_32(v):
v = from_long(v, 0, 256, lambda x: x)
if len(v) > 32:
raise ValueError("input to to_bytes_32 is too large")
return ((b'\0' * 32) + v)[-32:]
def bytetohex(byteStr):
return ''.join( [ "%02X" % x for x in byteStr ] ).strip()
litecoin = [b"\x30", b"\xb0"]
dogecoin = [b"\x1e", b"\x71"]
bitcoin = [b"\x00", b"\x80"]
dash = [b"\x4c", b"\xcc"]
if coinname == "LTC": cointype = litecoin
elif coinname == "BTC": cointype = bitcoin
elif coinname == "DOGE": cointype = dogecoin
elif coinname == "DASH": cointype = dash
#process all keys
if mode == 'check':
fKeyListFiltered = open(str(location)+"\\unique_keys_"+coinname+".txt", "r")
keylist = []
for privkey in fKeyListFiltered:
privkey = privkey.strip()
if privkey not in keylist and privkey != '':
keylist.append(privkey)
keylist.sort()
for key in keylist:
key = bytes.fromhex(key)
public_x, public_y = public_pair_for_secret_exponent(generator_secp256k1, int(bytetohex(key), 16))
public_key = b'\4' + to_bytes_32(public_x) + to_bytes_32(public_y)
compressed_public_key = bytes.fromhex("%02x%064x" % (2 + (public_y & 1), public_x))
m = hashlib.new('ripemd160')
m.update(hashlib.sha256(public_key).digest())
ripe = m.digest()
m = hashlib.new('ripemd160')
m.update(hashlib.sha256(compressed_public_key).digest())
ripe_c = m.digest()
extRipe = cointype[0] + ripe
extRipe_c = cointype[0] + ripe_c
chksum = hashlib.sha256(hashlib.sha256(extRipe).digest()).digest()[:4] # Step 5-7
chksum_c = hashlib.sha256(hashlib.sha256(extRipe_c).digest()).digest()[:4] # Step 5-7
addr = extRipe + chksum
addr_c = extRipe_c + chksum_c
keyWIF = cointype[1] + key
keyWIF_c = cointype[1] + key + b"\x01"
chksum = hashlib.sha256(hashlib.sha256(keyWIF).digest()).digest()[:4]
chksum_c = hashlib.sha256(hashlib.sha256(keyWIF_c).digest()).digest()[:4]
addr = keyWIF + chksum
addr_c = keyWIF_c + chksum_c
str(bytetohex(key))
private_key_static = str(bytetohex(key))
extended_key = "80"+private_key_static
first_sha256 = hashlib.sha256(binascii.unhexlify(extended_key)).hexdigest()
second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()
final_key = extended_key+second_sha256[:8]
WIF = base58.b58encode(binascii.unhexlify(final_key))
str(WIF)
CWIF = base58.b58encode(addr_c)
str(CWIF)
pkey = Key(secret_exponent=int.from_bytes(key, 'big'))
pkey._netcode = coinname
address = pkey.address()
fNoBalance = open(str(location)+"\\no_balance_"+coinname+".txt", "a")
fHasBalance = open(str(location)+"\\has_balance_"+coinname+".txt", "a")
success = False
while success == False:
#sleep(0.1) #enable/adjust this if you are getting rate limited or blocked.
sleep(1)
success = False
if coinname == 'BTC': req = 'https://insight.bitpay.com/api/addr/'+address+'/balance'
elif coinname == 'LTC': req = 'https://insight.litecore.io/api/addr/'+address+'/balance'
elif coinname == 'DASH': req = 'https://insight.dash.org/api/addr/'+address+'/balance'
elif coinname == 'DOGE': req = ' https://dogechain.info/api/v1/address/balance/'+address
print(req)
response = requests.get(req)
if response.status_code == 200:
content = response.json()
if coinname == 'DOGE':
balance = float(content['balance'])
else:
balance = content / 100000000
out = "ADD:"+address+" BAL: "+str(balance)+" WIF:" + str(CWIF)[2:99][:-1] + "\n"
print(out)
if balance == 0: fNoBalance.write(out)
else:
fHasBalance.write(out)
print("\a")
success = True
continue
#Gather all keys
elif mode == 'gather':
walletHandle = []
for file in glob.glob(str(location)+"/*.dat"):
if file.endswith('.dat'):
print(file)
walletHandle = open(file, "rb")
wallet = walletHandle.read()
privKeys_re_c=re.compile(b'\x30\x81\xD3\x02\x01\x01\x04\x20(.{32})', re.DOTALL)
privKeys=set(privKeys_re_c.findall(wallet))
print("Found %d privKeys" % len(privKeys))
fKeyList = open(str(location)+"\\all_keys_"+coinname+".txt", "a")
for key in privKeys:
#add to file containing ALL keys, just to make sure we don't accidently lose any data
fKeyList.write(str(bytetohex(key))+"\n")
continue
else:
continue
fKeyList = open(str(location)+"\\all_keys_"+coinname+".txt", "r")
keylist = []
for privkey in fKeyList:
privkey = privkey.strip()
if privkey not in keylist and privkey != '':
keylist.append(privkey)
fKeyListFiltered = open(str(location)+"\\unique_keys_"+coinname+".txt", "w+")
for privkey in fKeyListFiltered:
privkey = privkey.strip()
if privkey not in keylist and privkey != '':
keylist.append(privkey)
keylist.sort()
#print("\n".join(keylist))
fKeyListFiltered.write("\n".join(keylist))
walletHandle.close()