Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: 12 Word Mnemonic - Brute Force the Order?
by
Lattice Labs
on 08/09/2023, 06:11:12 UTC
⭐ Merited by odolvlobo (1)
Guys, Recovering the order of your 12 mnemonic words can be challenging, but it's important to approach this with caution, especially if you have a small amount of Bitcoin involved. Here's a basic Python script that you can use to generate permutations of your mnemonic words and check them against a Bitcoin wallet to see if they are valid:

from itertools import permutations
from hashlib import sha256
import hmac
import binascii

# List of your 12 mnemonic words
mnemonic_words = ["word1", "word2", ...]  # Replace with your actual words

# Your Bitcoin address and the checksum
bitcoin_address = "your_bitcoin_address"
checksum = "your_checksum_word"  # The last word in the list

# Function to check if a permutation is valid
def is_valid_permutation(permuted_words):
    # Recreate the mnemonic phrase with the current permutation
    phrase = " ".join(permuted_words)
   
    # Calculate the seed from the phrase (with or without the checksum word)
    seed = binascii.hexlify(hmac.new(phrase.encode(), b"mnemonic", sha256).digest()).decode()

    # Derive the Bitcoin address from the seed
    # Replace the following line with your Bitcoin wallet derivation logic
    derived_address = derive_address_from_seed(seed)

    # Compare the derived address with your actual Bitcoin address
    return derived_address == bitcoin_address

# Function to derive a Bitcoin address from a seed (you need to implement this)
def derive_address_from_seed(seed):
    # Implement your Bitcoin address derivation logic here
    # This would depend on the specific wallet software you used

# Generate all permutations of your mnemonic words
word_permutations = permutations(mnemonic_words)

# Iterate through permutations and check if they are valid
for permuted_words in word_permutations:
    if is_valid_permutation(permuted_words):
        print("Valid order found:", " ".join(permuted_words))
        break

You need to replace "word1", "word2", etc., with your actual mnemonic words and implement the derive_address_from_seed function according to the wallet software you used.

This script generates permutations and checks each one. With 12 words, there are indeed 479,001,600 possible permutations, so this method could be time-consuming.

The BIP39 checksum is used to detect errors in the mnemonic phrase, but it won't help you recover the correct word order.

Be cautious with your Bitcoin wallet and private keys, and consider seeking professional assistance if you're not comfortable with this process, especially given the potential loss of funds.