import argparse
import binascii
import hashlib
import base58
import os
import time
import random
import secp256k1 as ice
import secrets

# Import the bitcoinlib library
import bitcoinlib


# Import the bit library
import bit
from bloomfilter import BloomFilter, ScalableBloomFilter, SizeGrowthRate
from bip32utils import BIP32Key 
from bip32utils import BIP32_HARDEN
from mnemonic import Mnemonic


start_time_overall = time.time()  # Get the current time


def find_key_worker(mnemonic_phrase, language, strength, tree, childs, start_time, bloom_filtereth1, bloom_filtereth2):
    elapsed_time = time.time() - start_time
    # Generate the mnemonic phrase using the Mnemonic class
    mnemonic_obj = Mnemonic(language)
    mnemonic_words = mnemonic_phrase
    print("Currently checking: ", mnemonic_words)
    print("------------------")

    # Generate the BIP39 seed from the mnemonic phrase
    bip39_seed = mnemonic_obj.to_seed(mnemonic_words)

    # Use the BIP39 seed to create the root BIP-32 key
    root_key = BIP32Key.fromEntropy(bip39_seed)

    for t in range(tree):
        # Increment the account index for each tree
        current_account_index = t
        print(current_account_index)

        for i in range(childs):
            # Increment the account index and address index for each child
            current_address_index = i
            print(current_address_index)
            
            # Derive the Ethereum private key from the root key for derivation path ETH m/44'/60'/x'/0/y for Metamask
            child_key_eth = root_key.ChildKey(44 + BIP32_HARDEN).ChildKey(60 + BIP32_HARDEN).ChildKey(current_account_index + BIP32_HARDEN).ChildKey(0).ChildKey(current_address_index)
            eth_private_key = child_key_eth.PrivateKey()
            eth_private_key_hex = binascii.hexlify(eth_private_key)
            private_key_int_eth = int(eth_private_key_hex, 16)
            #print(eth_private_key_hex)

            # Convert the keys to Ethereum addresses
            eth_address = ice.privatekey_to_ETH_address(private_key_int_eth)
            eth_address_without_prefix = eth_address.strip("0x")
            #print(eth_address_without_prefix)

            # Derive the Ethereum private key from the root key for derivation path ETH m/44'/60'/0'/0/y for MyEtherWallet & Ledger Live
            child_key_eth2 = root_key.ChildKey(44 + BIP32_HARDEN).ChildKey(60 + BIP32_HARDEN).ChildKey(0 + BIP32_HARDEN).ChildKey(0).ChildKey(current_address_index)
            eth_private_key2 = child_key_eth2.PrivateKey()
            eth_private_key_hex2 = binascii.hexlify(eth_private_key2)
            private_key_int_eth2 = int(eth_private_key_hex2, 16)
            #print(eth_private_key_hex)

            # Convert the keys to Ethereum addresses
            eth_address2 = ice.privatekey_to_ETH_address(private_key_int_eth)
            eth_address_without_prefix2 = eth_address2.strip("0x")
            #print(eth_address_without_prefix2)

            # Check the Ethereum public address against the Ethereum bloom filter
            if eth_address_without_prefix in bloom_filtereth1 or eth_address_without_prefix in bloom_filtereth2:
                # The Ethereum public address has been seen before in bloom filter
                with open(eth_address, '.txt', 'w') as f:
                    # Write the mnemonic phrase to the file and return True
                    f.write("Ethereum address: {}\n".format(eth_address))
                    f.write("---------")
                    f.write("Mnemonic phrase: {}\n".format(mnemonic_words))
                    f.write("---------")
                    f.write("Account index derivation path: {}\n".format(current_account_index))
                    f.write("---------")
                    f.write("Address index derivation path: {}\n".format(current_address_index))
                    f.write("---------")
                    f.write("Private key HEX: {}\n".format(eth_private_key_hex))
                    f.write("---------")
                    # Print the informations
                    print("Found ETH: ")
                    print("---------")
                    print("Ethereum address: {}\n".format(eth_address))
                    print("---------")
                    print("Mnemonic phrase: {}\n".format(mnemonic_words))
                    print("---------")
                    print("Account index derivation path: {}\n".format(current_account_index))
                    print("---------")
                    print("Address index derivation path: {}\n".format(current_address_index))
                    print("---------")
                    print("Private key HEX: {}\n".format(eth_private_key_hex))
                    print("---------")
                    # Print the elapsed time
                    print("Time elapsed before finding ETH: {} seconds".format(time.time() - start_time_overall))
                    print("---------")
                return False

            # Check the Ethereum public address against the Ethereum bloom filter
            if eth_address_without_prefix2 in bloom_filtereth1 or eth_address_without_prefix2 in bloom_filtereth2:
                # The Ethereum public address has been seen before in bloom filter
                with open(eth_address2, '.txt', 'w') as f:
                    # Write the mnemonic phrase to the file and return True
                    f.write("Ethereum address: {}\n".format(eth_address2))
                    f.write("---------")
                    f.write("Mnemonic phrase: {}\n".format(mnemonic_words))
                    f.write("---------")
                    f.write("Account index derivation path: {}\n".format(current_account_index))
                    f.write("---------")
                    f.write("Address index derivation path: {}\n".format(current_address_index))
                    f.write("---------")
                    f.write("Private key HEX: {}\n".format(eth_private_key_hex2))
                    f.write("---------")
                    # Print the informations
                    print("Found ETH: ")
                    print("---------")
                    print("Ethereum address: {}\n".format(eth_address2))
                    print("---------")
                    print("Mnemonic phrase: {}\n".format(mnemonic_words))
                    print("---------")
                    print("Account index derivation path: {}\n".format(current_account_index))
                    print("---------")
                    print("Address index derivation path: {}\n".format(current_address_index))
                    print("---------")
                    print("Private key HEX: {}\n".format(eth_private_key_hex2))
                    print("---------")
                    # Print the elapsed time
                    print("Time elapsed before finding ETH: {} seconds".format(time.time() - start_time_overall))
                    print("---------")
                return False


    # Return False if the Bitcoin or Ethereum or Litecoin public address was not found in the bloom filters
    #print("Generated and checked all accounts & addresses index... Restart")
    #print("---------")
    return False

def main():
    start_time = time.time()  # Get the current time

    # Parse the command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("-l", "--language", type=str, help="Language of the mnemonic phrase (english, french, italian, japanese, chinese_simplified, chinese_traditional, korean, spanish)")
    parser.add_argument("-s", "--strength", type=str, help="Length of the mnemonic phrase (128, 160, 192, 224, 256, or 'random')")
    parser.add_argument("-c", "--childs", type=int, help="Number of child keys to generate")
    parser.add_argument("-t", "--tree", type=int, help="Number of trees to generate for the Bitcoin derivation path (default 100)")
    args = parser.parse_args()

    # Set the default values for the command-line arguments
    language = args.language if args.language else "english"
    strength = args.strength if args.language else 128
    childs = args.childs if args.childs else 4294967295
    tree = args.tree if args.tree else 2147483647


    with open('eth1.bf', "rb") as fp:
        bloom_filtereth1 = BloomFilter.load(fp)

    with open('eth2.bf', "rb") as fp:
        bloom_filtereth2 = BloomFilter.load(fp)

    # Read mnemonic phrases from the text file
    with open('mnemonic_phrases.txt', 'r') as file:
        mnemonic_phrases = file.readlines()


    addr_count = len(bloom_filtereth2)
    
    print("Mnemonic research for Ethereum by Kratos") 
    print("Total Ethereum addresses loaded: ", addr_count)    
    print("Launch of the research... May the (brute) force be with you!")
    print("-----------------------------------------------------------")

    # Iterate through each mnemonic phrase and find the key
    for mnemonic_phrase in mnemonic_phrases:
        # Clean up the mnemonic phrase (remove leading/trailing spaces and newlines)
        mnemonic_phrase = mnemonic_phrase.strip()
        if mnemonic_phrase:
            find_key_worker(mnemonic_phrase, language, strength, tree, childs, start_time, bloom_filtereth1, bloom_filtereth2)
        pass


# Call the main function

if __name__ == "__main__":
    main() 

Python Online Compiler

Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.

Taking inputs (stdin)

OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.

import sys
name = sys.stdin.readline()
print("Hello "+ name)

About Python

Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.

Tutorial & Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition IF-ELSE is used.

if conditional-expression
    #code
elif conditional-expression
    #code
else:
    #code

Note:

Indentation is very important in Python, make sure the indentation is followed correctly

2. For:

For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.

Example:

mylist=("Iphone","Pixel","Samsung")
for i in mylist:
    print(i)

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while condition  
    #code 

Collections

There are four types of collections in Python.

1. List:

List is a collection which is ordered and can be changed. Lists are specified in square brackets.

Example:

mylist=["iPhone","Pixel","Samsung"]
print(mylist)

2. Tuple:

Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.

Example:

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)

Below throws an error if you assign another value to tuple again.

myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)

3. Set:

Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.

Example:

myset = {"iPhone","Pixel","Samsung"}
print(myset)

4. Dictionary:

Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.

Example:

mydict = {
    "brand" :"iPhone",
    "model": "iPhone 11"
}
print(mydict)

Supported Libraries

Following are the libraries supported by OneCompiler's Python compiler

NameDescription
NumPyNumPy python library helps users to work on arrays with ease
SciPySciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation
SKLearn/Scikit-learnScikit-learn or Scikit-learn is the most useful library for machine learning in Python
PandasPandas is the most efficient Python library for data manipulation and analysis
DOcplexDOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling