You are on page 1of 2

import hashlib

import os
import multiprocessing
from Crypto.Random import get_random_bytes
from Crypto.Hash import SHA256
from Crypto.PublicKey import ECC
from datetime import datetime
import subprocess

count = multiprocessing.Value('i', 0) # shared counter


chunk_size = 1000 # print progress every 1000 keys

def read_target_addresses(filename):
"""Reads target addresses from a file."""
with open(filename, 'r') as f:
return set(line.strip() for line in f)

def generate_private_key(target_addresses, privkey_queue):


global count
while True:
# Generate a random private key
rng = get_random_bytes
privkey = int.from_bytes(rng(32), byteorder='big')

# Derive the corresponding public key and Ethereum address


pubkey = ECC.construct(curve='NIST P-256',
d=privkey).public_key().export_key(format='DER')
pubkey_hash = SHA256.new(pubkey[1:])
address = '0x' + hashlib.new('ripemd160', pubkey_hash.digest()).hexdigest()
[-40:]

with count.get_lock():
count.value += 1

# Print progress every chunk_size keys


if count.value % chunk_size == 0:
print(f"{count.value} keys processed")

# Check if the derived address matches any of the target addresses


if address in target_addresses:
print(f"\nFound matching private key: {privkey:064x} for address
{address}")
with open('found_keys.txt', 'a') as f:
f.write(f"{datetime.now()} - {privkey:064x} for address {address}\
n")
subprocess.call(['open', 'found_keys.txt'])
privkey_queue.put(privkey)
target_addresses.remove(address)
if not target_addresses:
print("All target addresses found.")
return

if __name__ == '__main__':
target_address_file = 'eth_addy.txt'
target_addresses = read_target_addresses(target_address_file)
num_processes = multiprocessing.cpu_count() # use all available CPU cores
privkey_queue = multiprocessing.Queue()

processes = []
for _ in range(num_processes):
p = multiprocessing.Process(target=generate_private_key,
args=(target_addresses, privkey_queue))
processes.append(p)
p.start()

for p in processes:
p.join()

while not privkey_queue.empty():


privkey = privkey_queue.get()
# Do something with the found private keys

You might also like