Post
Topic
Board Bitcoin Technical Support
Merits 5 from 1 user
Re: Private Key bad transcription recovery
by
deepceleron
on 17/04/2016, 09:21:04 UTC
⭐ Merited by ETFbitcoin (5)
The wallet import format has a checksum in it just like Bitcoin addresses. It is possible to quickly determine if a candidate "recovered" key is valid:

WIF checksum checking

1 - Take the Wallet Import Format string
Code:
   5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ

2 - Convert it to a byte string using Base58Check encoding
Code:
   800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D

3 - is the beginning byte string 0x80? If not, invalid.

4 - Drop the last 4 checksum bytes from the byte string
Code:
   800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D

5 - Perform SHA-256 hash on the shortened string
Code:
   8147786C4D15106333BF278D71DADAF1079EF2D2440A4DDE37D747DED5403592

6 - Perform SHA-256 hash on result of SHA-256 hash
Code:
   507A5B8DFED0FC6FE8801743720CEDEC06AA5C6FCA72B07C49964492FB98A714

7 - Take the first 4 bytes of the second SHA-256 hash, this is the checksum
Code:
   507A5B8D

8 - Is #7 the same as the last 4 bytes of #2? If not, invalid.

If we have such a checking routine that can try hundreds of WIF key checksums per second, then all we need to do is feed different text possibilities into the validator logically. It may be possible to programmatically find the private key with several characters mistranscribed or missing:

- Starts with "5"? No? Add "5" if missing characters; substitute "5" if right length; add "5" and drop other characters if right length;
- Correct Length: substitute alternate upper/lower case for one character, check all positions for one character wrong, then iterate for increasing numbers of multiple incorrect cases, incorrect letters, etc;
- Missing one character? Try adding all Base58 characters at all positions.

Missing two characters? It becomes a slightly harder problem. Adding two characters in all possible positions = 3,956,064 possibilities (if the 5 at the start is correct). Single-threaded python does about 300,000 SHA256 hashes a second on my PC, so probably less than a minute to try all.

This might be an interesting programming project, but I wouldn't bother until it's actually going to recover some Bitcoins.