Skip to content

Commit

Permalink
Update PyVanityGen.py
Browse files Browse the repository at this point in the history
  • Loading branch information
curly60e authored Oct 21, 2024
1 parent b70b188 commit 2645f38
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions pybitblock/SPV/PyVanityGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,60 @@
import os
import random
import multiprocessing
import logging
from bitcoinlib.keys import HDKey
from rich.console import Console
from rich.panel import Panel
from rich.live import Live
from rich.layout import Layout
from rich.text import Text
from queue import Empty
import base58

# Set up debug logging
logging.basicConfig(filename='debugfile.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

# Set up results logging
results_logger = logging.getLogger('results_logger')
results_logger.setLevel(logging.INFO)
results_handler = logging.FileHandler('Results.log')
results_handler.setFormatter(logging.Formatter('%(asctime)s - %(message)s'))
results_logger.addHandler(results_handler)

def privkey_to_wif(privkey, compressed=True, testnet=False):
prefix = b'\xEF' if testnet else b'\x80'
key_bytes = privkey.to_bytes(32, 'big')
if compressed:
key_bytes += b'\x01'
extended_key = prefix + key_bytes
checksum = extended_key + extended_key[:4]
wif = base58.b58encode(extended_key + checksum[:4]).decode('utf-8')
return wif

def address_search(search_for, witness_type, progress_queue, console):
privkey = random.randrange(2**256)
address = ''
count = 0

bech32 = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
is_bech32 = True
is_base58 = True
for letter in search_for:
if letter not in bech32:
is_bech32 = False
if letter not in base58:
is_base58 = False
if not (is_bech32 or is_base58):
raise ValueError(f"This is not a valid base58 or bech32 search string: {search_for}")
if is_base58 and not is_bech32:
witness_type = 'p2sh-segwit'

logging.info(f"Searching for {search_for}, witness_type is {witness_type} (pid {os.getpid()})")
console.print(f"[yellow]Searching for {search_for}, witness_type is {witness_type} (pid {os.getpid()})[/yellow]")

while True:
privkey += 1
k = HDKey(witness_type=witness_type)
address = k.address()
count += 1
progress_queue.put(f"Searched {count} addresses (pid {os.getpid()})")
if search_for in address:
progress_queue.put(f"Found Address: {address}\nPrivate Key HEX: {k.private_hex}")
try:
privkey += 1
k = HDKey(key=privkey.to_bytes(32, 'big'), witness_type=witness_type)
address = k.address()
count += 1
progress_queue.put(f"Searched {count} addresses (pid {os.getpid()})")
if search_for in address:
wif_key = privkey_to_wif(privkey)
result_message = f"Found Address: {address}\nPrivate Key WIF: {wif_key}"
progress_queue.put(result_message)
logging.info(result_message)
results_logger.info(result_message)
# Continue searching instead of breaking to find more vanity addresses
except Exception as e:
logging.error(f"Error during address search: {e}")
break

def main():
Expand All @@ -51,10 +68,10 @@ def main():

# Seleccionar texto deseado en la direcciΓ³n
search_for = console.input("Put your word for the vanity address: ").strip()

# Iniciar los procesos
processors = 4
console.print(f"[green]Starting {processors} processes[/green]")
logging.info(f"Starting {processors} processes for vanity address search")

layout = Layout()
layout.split(
Expand All @@ -72,6 +89,7 @@ def main():
ps = []
for i in range(processors):
console.print(f"[cyan]Starting process {i}[/cyan]")
logging.info(f"Starting process {i}")
p = multiprocessing.Process(target=address_search, args=(search_for, witness_type, progress_queue, console))
p.start()
ps.append(p)
Expand All @@ -84,6 +102,8 @@ def main():
message = progress_queue.get(timeout=1)
if "Found Address" in message:
result_messages.append(message)
if len(result_messages) > 10:
result_messages.pop(0) # Keep only the last 10 results
result_panel = Panel(Text("\n".join(result_messages)), title="Results", border_style="green")
layout["results"].update(result_panel)
else:
Expand All @@ -97,6 +117,7 @@ def main():
pass
except KeyboardInterrupt:
console.print("[red]Stopping processes...[/red]")
logging.info("Stopping processes due to KeyboardInterrupt")
for p in ps:
p.terminate()
for p in ps:
Expand Down

0 comments on commit 2645f38

Please sign in to comment.