Post
Topic
Board Development & Technical Discussion
Re: Claim the coins challenge - The typo scenario
by
ius
on 30/06/2011, 16:33:14 UTC
A single typo is trivial to correct, as the private key includes a checksum as well.

Warning: hackjob ahead
Code:
#!/usr/bin/python
import base58, hashlib

def sha_checksum(data):
    return hashlib.sha256(hashlib.sha256(data).digest()).digest()[:4]

sec = '5JjNVWPaRTPg1i4etqfPHFnsDZ1Js5qBYXFH9G4jC2Drb6kERsm'

data = base58.b58decode(sec, 37)

checksum = data[-4:]
key = data[:-4]

for i in xrange(len(sec)):
    for c in base58.__b58chars:
        modkey = sec[:i] + c + sec[i+1:]
        decoded = base58.b58decode(modkey, 37)

        if decoded:
            if sha_checksum(decoded[:-4]) == checksum:
                print 'Found:', modkey
                print (6+base58.__b58chars.index(c))*' '+'^'

Code:
Output:Found: 5JjNVWPaRTPg1i4etqfPHPnsDZ1Js5qBYXFH9G4jC2Drb6kERsm
                                   ^

Hmm, no monospaced code font?