Hello friend!

In this video we will use AI to code a Python script that can help you in recovering your lost bitcoin wallet.

More precisely we will be using Google’s AI Studio to work out a little tool capable of assisting in bitcoin wallet recovery with the use of brute-forcing the original words that form your seed phrase.

The purpose for this article is to guide you on the use of this tool but also to show you how to approach using AI for creating simple tools to help you in your repetitive daily tasks. With AI being so widespread and easy to use right now it is a good idea to think of what tools you can create to automate certain tasks and save your precious time. But before we begin…

InstructionsDownload

You can get this project from Github: CryptoBrute

Let’s get started. For macOS operating system we will use Homebrew to install the correct version of Python whereas for Windows you should download it directly from Python.org.

I am assuming you already have pip installed. If not follow the official tutorial to install it since we will be using pip to download the required dependencies for this project.

  1. Install Python 3.12
    • mac: brew install python@3.12
    • windows: manually download and install Python3.12.13
  2. Create a virtual environment
    • python3.12 -m venv venv_stable
    • source venv_stable/bin/activate
  3. Install dependencies
    • pip install coincurve
    • pip install bip-utils
    • pip install requests

If you had no error messages, that’s it. You are done. Just remember the location of your virtual environment so you can quickly access it at a later time or you will have to recreate it.

AI Code Methodology

As I mentioned previously the purpose of this post is to highlight how fast we can go from a simple idea into a complete script with a menu and several different options.

My main methodology focuses on the core function of the script. Whatever that is, I always try to get AI to cook a simplified version of it to begin with. Let’s use this idea for example, the bitcoin wallet recovery tool. My initial thought was to just import a wallet properly and view it’s contents.

That was enough to where I could peep the script, view the libraries imported and have an idea of how to use these libraries and what checks they were doing overall. Once I understood that, then I proceeded with adding an online check for the wallet using mempool.space (although there is an option to change in the settings).

Finally I was able to implement the wordlist containing all 2048 words for the brute-force mask attack.

Of course there were many errors along the way but using AI I was able to simply paste the error output and give it some context and it would quickly help me identify the issue and fix it.

Bitcoin Wallet Security

Overall I think its safe to say that Bitcoin encryption is extremely safe and secure. Although Google recently posted news about advances in using quantum computers for breaking the 256-bit elliptic curve cryptography, for the time being, the encryption is nearly unbreakable.

One of the cool things of using AI to do these scripts is we get to learn a lot about the inner workings naturally throughout the prompting process. Here I’ll post some of this content that helped me digest how Bitcoin wallets work and why some things are possible while others aren’t.

How It Works: The Cryptographic Pipeline

Recovering a wallet isn’t magic; it’s a standardized mathematical process. Here are the steps involved, which our script will follow:

  1. Mnemonic (Seed Phrase) → Seed (BIP-39): Your 12, 18, or 24-word phrase is converted into a 512-bit binary “seed”. This is the root of your entire wallet. An optional passphrase can be added for extra security (sometimes called the “13th/25th word”).
  2. Seed → Master Private Key (BIP-32): The 512-bit seed is used to generate a master private key and a master chain code. This is the top-level key of your “HD Wallet tree.”
  3. Master Key → Child Keys (BIP-32): Using a process called “derivation,” we can create a nearly infinite tree of child keys from the master key. This is done using a derivation path.
  4. Derivation Path (BIP-44, BIP-49, BIP-84): This is a structured path that tells the wallet which specific keys to derive. A standard path looks like this:
    m / purpose’ / coin_type’ / account’ / change / address_index
    • purpose’: Defines the address type.
      • 44′: Legacy addresses (start with 1…)
      • 49′: Nested SegWit addresses (start with 3…)
      • 84′: Native SegWit addresses (start with bc1q…)
    • coin_type’: 0′ for Bitcoin.
    • account’: Organizes funds into separate accounts (e.g., 0′ for the first account).
    • change: 0 for receiving addresses, 1 for change addresses.
    • address_index: The specific address (0, 1, 2, …).
  5. Child Private Key → Public Key → Bitcoin Address: Each derived child private key has a corresponding public key, which is then hashed to create the final, shareable Bitcoin address.

However, we must address a critical cryptographic detail first.

Why We Can’t Just Pick 12 Random Words

A valid BIP-39 mnemonic phrase is not just 12 random words from the list. It’s actually:

  • 11 and a fraction random words: These are derived from a random number (128 bits of entropy for a 12-word phrase).
  • A checksum: The last few bits of the 12th word are a checksum calculated from the initial random number.

This is why the MnemonicChecksumError you saw earlier exists. If you pick 12 truly random words, the odds of the checksum being correct by chance are astronomically low (1 in 16 for a 12-word phrase). The script would fail almost every single time.

The Correct Approach (The “Spirit” of Your Request)

Instead of picking random words and hoping for the best, we can do what wallets do:

  1. Generate a cryptographically secure random number.
  2. Use the bip_utils library to correctly convert this number into a valid 12-word mnemonic phrase.

This achieves your goal of starting with a new, random, and valid mnemonic each time the script runs. We will still use your english.txt file as the foundation, as the library needs that wordlist to perform the conversion.

🚨 EXTREMELY IMPORTANT: A Word on Probability

What you are asking to do is technically possible, but it is statistically impossible to succeed in a human lifetime, or even in the lifetime of the universe.

  • The number of possible 12-word Bitcoin wallets is 2¹²⁸.
  • This number is 340,282,366,920,938,463,463,374,607,431,768,211,456.
  • This is roughly equivalent to the estimated number of atoms in our entire galaxy.

Even if your computer could check one trillion wallets per second (which is vastly beyond its capability), it would take billions of years to have even a remote chance of finding a single satoshi.

Share: