import itertools
import hashlib
import ecdsa
from bip38 import decrypt_bip38_key
from bitcoin import address_from_private_key
import time
# Your BIP-38 encrypted key and confirmation code
encrypted_key = "6PnQmAyBky9ZXJyZBv9QSGRUXkKh9HfnVsZWPn4YtcwoKy5vufUgfA3Ld7" #
Replace with your encrypted key
target_address = "1QGtbKxx6FKDD66LwnrzHCAHmyZ7mDHqC4"
# Helper function to check if the address matches the target
def generate_bitcoin_address_from_private_key(private_key):
private_key_bytes = bytes.fromhex(private_key)
sk = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1)
vk = sk.get_verifying_key()
pubkey = b'\x04' + vk.to_string() # Uncompressed public key
sha256_pubkey = hashlib.sha256(pubkey).digest()
ripemd160_pubkey = hashlib.new('ripemd160', sha256_pubkey).digest()
address = address_from_private_key(private_key)
return address
# Smart passphrase generator (using XXXX-XXXX-XXXX-XXXX-XXXX format)
def generate_passphrase():
charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" # Alphanumeric plus '-'
length = 4 # Length of each segment
for comb in itertools.product(charset, repeat=length):
yield ''.join(comb)
def brute_force_passphrase():
for passphrase in generate_passphrase():
print(f"Trying passphrase: {passphrase}")
decrypted_private_key = decrypt_bip38_key(encrypted_key, passphrase)
if decrypted_private_key:
generated_address =
generate_bitcoin_address_from_private_key(decrypted_private_key)
print(f"Generated Address: {generated_address}")
if generated_address == target_address:
print(f"✅ Found the correct passphrase: {passphrase}")
return passphrase # Return the correct passphrase
else:
print(f"❌ Invalid passphrase: {passphrase}")
time.sleep(0.1) # Small delay to prevent overloading
# Run the brute-force search
if __name__ == "__main__":
brute_force_passphrase()