Skip to content

Instantly share code, notes, and snippets.

@iulianbadoi
Forked from UdjinM6/bitwalletrecover.py
Created October 19, 2018 19:18
Show Gist options
  • Select an option

  • Save iulianbadoi/d70121c9f1dfccea9aab5ac9182a9695 to your computer and use it in GitHub Desktop.

Select an option

Save iulianbadoi/d70121c9f1dfccea9aab5ac9182a9695 to your computer and use it in GitHub Desktop.

Revisions

  1. UdjinM6 revised this gist Oct 27, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,8 @@
    ## sudo pip install pycoin
    ## sudo pip install base58
    ##
    ## Donations are welcome :)
    ## DRK: XsV4GHVKGTjQFvwB7c6mYsGV3Mxf7iser6

    import re
    import hashlib
  2. UdjinM6 revised this gist Oct 27, 2014. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    ## bitwalletrecover.py - recover private keys from your darkcoin wallet (this version was not tested with bitcoin/litecoin).
    ## Requires python3, pycoin (https://pypi.python.org/pypi/pycoin), and base58 (https://pypi.python.org/pypi/base58).
    ##
    ## Starting with Python 3.4, pip is included by default with the Python binary installers.
    ## To install pip for older versions 3.x:
    ## bitwalletrecover.py - recover private keys from your darkcoin wallet
    ## (this version was not tested with bitcoin/litecoin).
    ## Requires python3, pycoin (https://pypi.python.org/pypi/pycoin),
    ## and base58 (https://pypi.python.org/pypi/base58).
    ##
    ## Starting with Python 3.4, pip is included by default with the Python binary
    ## installers. To install pip for older versions 3.x:
    ##
    ## sudo apt-get install python3-setuptools
    ## sudo easy_install3 pip
  3. UdjinM6 revised this gist Oct 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## bitwalletrecover.py - recover private keys from your darkcoin wallet (this version was nat tested with bitcoin/litecoin).
    ## bitwalletrecover.py - recover private keys from your darkcoin wallet (this version was not tested with bitcoin/litecoin).
    ## Requires python3, pycoin (https://pypi.python.org/pypi/pycoin), and base58 (https://pypi.python.org/pypi/base58).
    ##
    ## Starting with Python 3.4, pip is included by default with the Python binary installers.
  4. UdjinM6 revised this gist Oct 27, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## bitwalletrecover.py - recover private keys from your bitcoin/litecoin/darkcoin wallet.
    ## bitwalletrecover.py - recover private keys from your darkcoin wallet (this version was nat tested with bitcoin/litecoin).
    ## Requires python3, pycoin (https://pypi.python.org/pypi/pycoin), and base58 (https://pypi.python.org/pypi/base58).
    ##
    ## Starting with Python 3.4, pip is included by default with the Python binary installers.
    @@ -45,8 +45,8 @@ def to_bytes_32(v):
    def bytetohex(byteStr):
    return ''.join( [ "%02X" % x for x in byteStr ] ).strip()

    litecoin = [b"\x30", b"\xb0"]
    bitcoin = [b"\x00", b"\x80"]
    #litecoin = [b"\x30", b"\xb0"]
    #bitcoin = [b"\x00", b"\x80"]
    darkcoin = [b"\x4c", b"\xcc"]

    cointype = darkcoin
    @@ -66,7 +66,7 @@ def bytetohex(byteStr):
    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))

    #https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses
    ## https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

    m = hashlib.new('ripemd160')
    m.update(hashlib.sha256(public_key).digest())
    @@ -91,8 +91,8 @@ def bytetohex(byteStr):
    print("Public Address:", base58.b58encode(addr))
    print("Public Address Compressed:", base58.b58encode(addr_c))

    # WIF https://en.bitcoin.it/wiki/Wallet_import_format
    # compressed WIF http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development
    ## WIF https://en.bitcoin.it/wiki/Wallet_import_format
    ## compressed WIF http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development

    keyWIF = cointype[1] + key
    keyWIF_c = cointype[1] + key + b"\x01"
  5. UdjinM6 revised this gist Oct 27, 2014. 1 changed file with 12 additions and 5 deletions.
    17 changes: 12 additions & 5 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,16 @@
    ## bitwalletrecover.py - recover private keys from your bitcoin/litecoin/darkcoin wallet.
    ## Requires python3, pycoin (https://pypi.python.org/pypi/pycoin), and base58 (https://pypi.python.org/pypi/base58).
    ##
    ## Starting with Python 3.4, pip is included by default with the Python binary installers.
    ## To install pip for older versions 3.x:
    ##
    ## sudo apt-get install python3-setuptools
    ## sudo easy_install3 pip
    ## sudo apt-get install python3-setuptools
    ## sudo easy_install3 pip
    ##
    ## sudo pip install pycoin
    ## sudo pip install base58
    ## Install libs:
    ##
    ## sudo pip install pycoin
    ## sudo pip install base58
    ##

    import re
    @@ -99,4 +106,4 @@ def bytetohex(byteStr):
    print("Private Key WIF (51 Base58 characters):", base58.b58encode(addr))
    print("Private Key WIF Compressed (52 Base58 characters):", base58.b58encode(addr_c),"\n")

    walletHandle.close()
    walletHandle.close()
  6. UdjinM6 revised this gist Oct 27, 2014. 1 changed file with 56 additions and 14 deletions.
    70 changes: 56 additions & 14 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,32 @@
    import base58
    from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent

    def from_long(v, prefix, base, charset):
    """The inverse of to_long. Convert an integer to an arbitrary base.
    v: the integer value to convert
    prefix: the number of prefixed 0s to include
    base: the new base
    charset: an array indicating what printable character to use for each value.
    """
    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()
    return ''.join( [ "%02X" % x for x in byteStr ] ).strip()

    litecoin = [b"\x30", b"\xb0"]
    bitcoin = [b"\x00", b"\x80"]
    @@ -23,38 +47,56 @@ def bytetohex(byteStr):
    walletHandle = open("wallet.dat", "rb")
    wallet = walletHandle.read()

    privKeys=set(re.findall(b'\x70\x6F\x6F\x6C(.{52})', wallet))
    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))

    for key in privKeys:
    key = key[20:]


    public_x, public_y = public_pair_for_secret_exponent(generator_secp256k1, int(bytetohex(key), 16))
    compressed_public_key = bytes.fromhex("%02x%064x" % (2 + (public_y & 1), public_x))

    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))

    #https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

    m = hashlib.new('ripemd160')
    m.update(hashlib.sha256(compressed_public_key).digest())
    m.update(hashlib.sha256(public_key).digest())
    ripe = m.digest() # Step 2 & 3

    m = hashlib.new('ripemd160')
    m.update(hashlib.sha256(compressed_public_key).digest())
    ripe_c = m.digest() # Step 2 & 3

    extRipe = cointype[0] + ripe # Step 4
    extRipe_c = cointype[0] + ripe_c # Step 4


    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 # Step 8
    print("Address:", base58.b58encode(addr))
    addr_c = extRipe_c + chksum_c # Step 8

    print("Public Key (130 characters [0-9A-F]):", bytetohex(public_key))
    print("Public Key (compressed, 66 characters [0-9A-F]):", bytetohex(compressed_public_key))
    print("Public Address:", base58.b58encode(addr))
    print("Public Address Compressed:", base58.b58encode(addr_c))

    # WIF https://en.bitcoin.it/wiki/Wallet_import_format
    # compressed WIF http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development

    # compressed wallet import format http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development
    key = cointype[1] + key + b"\x01"
    keyWIF = cointype[1] + key
    keyWIF_c = cointype[1] + key + b"\x01"

    chksum = hashlib.sha256(hashlib.sha256(key).digest()).digest()[:4]

    addr = key + chksum # Step 8
    print("Private Key:", base58.b58encode(addr),"\n")
    chksum = hashlib.sha256(hashlib.sha256(keyWIF).digest()).digest()[:4]
    chksum_c = hashlib.sha256(hashlib.sha256(keyWIF_c).digest()).digest()[:4]

    addr = keyWIF + chksum # Step 8
    addr_c = keyWIF_c + chksum_c # Step 8
    print("Private Key Hexadecimal Format (64 characters [0-9A-F]):", bytetohex(key))
    print("Private Key WIF (51 Base58 characters):", base58.b58encode(addr))
    print("Private Key WIF Compressed (52 Base58 characters):", base58.b58encode(addr_c),"\n")

    walletHandle.close()
    walletHandle.close()
  7. UdjinM6 revised this gist Oct 26, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    ##
    ## sudo apt-get install python3-setuptools
    ## sudo easy_install3 pip
    ##
    ## sudo pip install pycoin
    ## sudo pip install base58
    ##

    import re
    import hashlib
    import base58
  8. UdjinM6 revised this gist Oct 26, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,11 @@ def bytetohex(byteStr):

    litecoin = [b"\x30", b"\xb0"]
    bitcoin = [b"\x00", b"\x80"]
    darkcoin = [b"\x4c", b"\xcc"]

    cointype = litecoin
    cointype = darkcoin

    walletHandle = open("C:/Users/alex/Downloads/litecoin-0.8.5.1-win32-setup/data/wallet.dat", "rb")
    walletHandle = open("wallet.dat", "rb")
    wallet = walletHandle.read()

    privKeys=set(re.findall(b'\x70\x6F\x6F\x6C(.{52})', wallet))
  9. @msm595 msm595 revised this gist Nov 28, 2013. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,14 @@
    from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent

    def bytetohex(byteStr):
    return ''.join( [ "%02X" % x for x in byteStr ] ).strip()
    return ''.join( [ "%02X" % x for x in byteStr ] ).strip()

    walletHandle = open("T:\litecoin-0.8.5.1-win32-setup\data2\wallet.dat", "rb")
    litecoin = [b"\x30", b"\xb0"]
    bitcoin = [b"\x00", b"\x80"]

    cointype = litecoin

    walletHandle = open("C:/Users/alex/Downloads/litecoin-0.8.5.1-win32-setup/data/wallet.dat", "rb")
    wallet = walletHandle.read()

    privKeys=set(re.findall(b'\x70\x6F\x6F\x6C(.{52})', wallet))
    @@ -26,7 +31,7 @@ def bytetohex(byteStr):
    m.update(hashlib.sha256(compressed_public_key).digest())
    ripe = m.digest() # Step 2 & 3

    extRipe = b"\x00" + ripe # Step 4
    extRipe = cointype[0] + ripe # Step 4

    chksum = hashlib.sha256(hashlib.sha256(extRipe).digest()).digest()[:4] # Step 5-7

    @@ -36,7 +41,7 @@ def bytetohex(byteStr):


    # compressed wallet import format http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development
    key = b"\x80" + key + b"\x01"
    key = cointype[1] + key + b"\x01"

    chksum = hashlib.sha256(hashlib.sha256(key).digest()).digest()[:4]

  10. @msm595 msm595 created this gist Nov 22, 2013.
    46 changes: 46 additions & 0 deletions bitwalletrecover.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    import re
    import hashlib
    import base58
    from pycoin.ecdsa import generator_secp256k1, public_pair_for_secret_exponent

    def bytetohex(byteStr):
    return ''.join( [ "%02X" % x for x in byteStr ] ).strip()

    walletHandle = open("T:\litecoin-0.8.5.1-win32-setup\data2\wallet.dat", "rb")
    wallet = walletHandle.read()

    privKeys=set(re.findall(b'\x70\x6F\x6F\x6C(.{52})', wallet))

    print("Found %d privKeys" % len(privKeys))

    for key in privKeys:
    key = key[20:]

    public_x, public_y = public_pair_for_secret_exponent(generator_secp256k1, int(bytetohex(key), 16))
    compressed_public_key = bytes.fromhex("%02x%064x" % (2 + (public_y & 1), public_x))


    #https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

    m = hashlib.new('ripemd160')
    m.update(hashlib.sha256(compressed_public_key).digest())
    ripe = m.digest() # Step 2 & 3

    extRipe = b"\x00" + ripe # Step 4

    chksum = hashlib.sha256(hashlib.sha256(extRipe).digest()).digest()[:4] # Step 5-7

    addr = extRipe + chksum # Step 8
    print("Address:", base58.b58encode(addr))



    # compressed wallet import format http://sourceforge.net/mailarchive/forum.php?thread_name=CAPg%2BsBhDFCjAn1tRRQhaudtqwsh4vcVbxzm%2BAA2OuFxN71fwUA%40mail.gmail.com&forum_name=bitcoin-development
    key = b"\x80" + key + b"\x01"

    chksum = hashlib.sha256(hashlib.sha256(key).digest()).digest()[:4]

    addr = key + chksum # Step 8
    print("Private Key:", base58.b58encode(addr),"\n")

    walletHandle.close()