Post
Topic
Board Bitcoin Discussion
Topic OP
Bitcoin address from 2014
by
ganzocrypt
on 22/12/2024, 13:21:45 UTC
Hello,

I am trying to "generate" bitcoin addresses from 2014 to see if they have some satoshi. It's for a friend who think he has the passphrase and wants to see if the addresses have Bitcoin!

I am using AI to create a script to do the following:
write a script to create bitcoin P2PKH and P2SH formats valid addresses starting from several passphrase. Print the passphrase for each address indicating the address formats. Check also if the address has bitcoins.


The scripts works but I do not know if these addresses are correct. I check on https://www.blockchain.com/explorer/ if these addresses exists and it tells me if they are P2PKH and P2SH format.
Any ideas?

Code:
import hashlib
import base58
import requests

def generate_p2pkh_address(passphrase):
    # Generate a public key from the passphrase
    private_key = hashlib.sha256(passphrase.encode()).hexdigest()
    public_key = hashlib.new('ripemd160', hashlib.sha256(bytes.fromhex(private_key)).digest()).hexdigest()
   
    # Create P2PKH address
    p2pkh_prefix = '00'
    p2pkh_address = p2pkh_prefix + public_key
    p2pkh_address_checksum = hashlib.sha256(hashlib.sha256(bytes.fromhex(p2pkh_address)).digest()).digest()[:4]
    p2pkh_address += p2pkh_address_checksum.hex()
    p2pkh_address = base58.b58encode(bytes.fromhex(p2pkh_address)).decode()
   
    return p2pkh_address

def generate_p2sh_address(passphrase):
    # Generate a public key from the passphrase
    private_key = hashlib.sha256(passphrase.encode()).hexdigest()
    public_key = hashlib.new('ripemd160', hashlib.sha256(bytes.fromhex(private_key)).digest()).hexdigest()
   
    # Create P2SH address
    p2sh_prefix = '05'
    p2sh_address = p2sh_prefix + public_key
    p2sh_address_checksum = hashlib.sha256(hashlib.sha256(bytes.fromhex(p2sh_address)).digest()).digest()[:4]
    p2sh_address += p2sh_address_checksum.hex()
    p2sh_address = base58.b58encode(bytes.fromhex(p2sh_address)).decode()
   
    return p2sh_address

def check_balance(address):
    response = requests.get(f'https://api.blockcypher.com/v1/btc/main/addrs/{address}/balance')
    if response.status_code == 200:
        return response.json()['final_balance']
    return None

passphrases = ['passphrase1', 'passphrase2', 'passphrase3']

for passphrase in passphrases:
    p2pkh_address = generate_p2pkh_address(passphrase)
    p2sh_address = generate_p2sh_address(passphrase)
   
    p2pkh_balance = check_balance(p2pkh_address)
    p2sh_balance = check_balance(p2sh_address)
   
    print(f'Passphrase: {passphrase}')
    print(f'P2PKH Address: {p2pkh_address}, Balance: {p2pkh_balance} satoshis')
    print(f'P2SH Address: {p2sh_address}, Balance: {p2sh_balance} satoshis')