I missed the recent activity in this thread.
Here's another script that substitutes replacements from the base58 character set for each character in the bad wif, and then inserts all base58 chars at each position in the string.
So it should deal with all private keys that have one missing character plus one mistranscribed character.
It takes about 15 minutes to run on my old, slow laptop, but I've included progress output so that you can tell something is at least happening.
import bitcoin.base58
from bitcoin.core import b2x, x
from bitcoin.core import Hash
import sys
def replace_char(string, char, i):
return string[:i]+char+string[i+1:]
def insert_char(string, char, i):
return string[:i+1]+char+string[i+1:]
def verify_wif_checksum(wif):
byte_string = b2x(bitcoin.base58.decode(wif))
private = byte_string[:-8]
checksum = byte_string[-8:]
return checksum == b2x(Hash(x(private)))[:8]
def candidate_wifs(corrupted_wif):
candidates = set()
for i in range(len(corrupted_wif)):
#print("%i of %i" % (i, len(corrupted_wif)),)
sys.stdout.write("%3i of %3i : " % (i, len(corrupted_wif)))
for char in bitcoin.base58.B58_DIGITS:
sys.stdout.write(char)
candidate_wif = replace_char(corrupted_wif, char, i)
for c in insertion_candidates(candidate_wif):
candidates.add(c)
print()
return candidates
def insertion_candidates(corrupted_wif):
candidates = []
for i in range(len(corrupted_wif)):
for char in bitcoin.base58.B58_DIGITS:
candidate_wif = insert_char(corrupted_wif, char, i)
if verify_wif_checksum(candidate_wif):
print("\nFound: %s" % candidate_wif)
candidates.append(candidate_wif)
return candidates
# Provide a WIF private key with a single missing character.
# Wrong Char v
corrupted_wif = '5HueCGU8rkjxEXxiPuD5BDku4kFqeZyd4dZ1jvhTVqvbTLvyTJ'
# Should be: '5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ'
# Missing Char ^
for candidate_wif in candidate_wifs(corrupted_wif):
print(candidate_wif)