Here's a script in python which uses deepceleron's idea of using the checksum to filter out bad candidates.
It does depend on python-bitcoinlib.
https://github.com/petertodd/python-bitcoinlibimport bitcoin.base58
from bitcoin.core import b2x, x
from bitcoin.wallet import CBitcoinSecret, P2PKHBitcoinAddress
from bitcoin.core import Hash
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 = []
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):
candidates.append(candidate_wif)
return candidates
# Provide a WIF private key with a single missing character.
corrupted_wif = '5HueCGU8rMjxEXxiPuD5BDku4kFqeZyd4dZ1jvhTVqvbTLvyTJ'
# Should be: '5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ'
for candidate_wif in candidate_wifs(corrupted_wif):
print(candidate_wif)
It should hopefully output any candidate private keys.
For example:
5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ