DEV Community

Cover image for Bitcoin Private Key Finder and Generator address , hack wallet with python
MMDRZA
MMDRZA

Posted on • Updated on

Bitcoin Private Key Finder and Generator address , hack wallet with python

Bitcoin Private Key Wallet Finder
Generator address and Private Key
Received input Range For user
use python 3.8 and Pycharm Professional , blockcypher , moneywagon urlib satoshi package for this project.

pip install blockcypher
pip install moneywagon
pip install urllib
pip install satoshi
Enter fullscreen mode Exit fullscreen mode

after install all package create file utils.py for config and setting base program . you can visit my youtube channel and follow this project video ( title youtube on my channel ):

Bitcoin Private Key Finder and Generator Auto With Python.
youtu.be/0MvjIxy4vBQ

bitcoin private key generator with python
after create file utils.py on director base project first import this package from this python coding :

from hashlib import sha256
from typing import Union

Enter fullscreen mode Exit fullscreen mode

after insert this package entered all cod on file utils.py :


class Point(object):
    def __init__(self, _x, _y, _order=None):
        self.x, self.y, self.order = _x, _y, _order

    def calc(self, top, bottom, other_x):
        ll = (top * inverse_mod(bottom)) % p
        x3 = (ll * ll - self.x - other_x) % p
        return Point(x3, (ll * (self.x - x3) - self.y) % p)

    def double(self):
        if self == INFINITY:
            return INFINITY
        return self.calc(3 * self.x * self.x, 2 * self.y, self.x)

    def __add__(self, other):
        if other == INFINITY:
            return self
        if self == INFINITY:
            return other
        if self.x == other.x:
            if (self.y + other.y) % p == 0:
                return INFINITY
            return self.double()
        return self.calc(other.y - self.y, other.x - self.x, other.x)

    def __mul__(self, e):
        if self.order:
            e %= self.order
        if e == 0 or self == INFINITY:
            return INFINITY
        result, q = INFINITY, self
        while e:
            if e & 1:
                result += q
            e, q = e >> 1, q.double()
        return result

    def __str__(self):
        if self == INFINITY:
            return "infinity"
        return "%x %x" % (self.x, self.y)


p, INFINITY = (
    0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F,
    Point(None, None),
)  # secp256k1
g = Point(
    0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798,
    0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8,
    0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141,
)


def inverse_mod(a):
    if a < 0 or a >= p:
        a = a % p
    c, d, uc, vc, ud, vd = a, p, 1, 0, 0, 1
    while c:
        q, c, d = divmod(d, c) + (c,)
        uc, vc, ud, vd = ud - q * uc, vd - q * vc, uc, vc
    if ud > 0:
        return ud
    return ud + p


BITCOIN_ALPHABET = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"


def scrub_input(v: Union[str, bytes]) -> bytes:
    if isinstance(v, str):
        v = v.encode("ascii")
    return v


def b58encode_int(
    i: int, default_one: bool = True, alphabet: bytes = BITCOIN_ALPHABET
) -> bytes:
    """
    Encode an integer using Base58
    """
    if not i and default_one:
        return alphabet[0:1]
    string = b""
    while i:
        i, idx = divmod(i, 58)
        string = alphabet[idx : idx + 1] + string
    return string


def b58encode(v: Union[str, bytes], alphabet: bytes = BITCOIN_ALPHABET) -> bytes:
    """
    Encode a string using Base58
    """
    v = scrub_input(v)

    nPad = len(v)
    v = v.lstrip(b"\0")
    nPad -= len(v)

    p, acc = 1, 0
    for c in reversed(v):
        acc += p * c
        p = p << 8
    result = b58encode_int(acc, default_one=False, alphabet=alphabet)
    return alphabet[0:1] * nPad + result


def b58decode_int(v: Union[str, bytes], alphabet: bytes = BITCOIN_ALPHABET) -> int:
    """
    Decode a Base58 encoded string as an integer
    """
    v = v.rstrip()
    v = scrub_input(v)

    decimal = 0
    for char in v:
        decimal = decimal * 58 + alphabet.index(char)
    return decimal


def b58decode(v: Union[str, bytes], alphabet: bytes = BITCOIN_ALPHABET) -> bytes:
    """
    Decode a Base58 encoded string
    """
    v = v.rstrip()
    v = scrub_input(v)

    origlen = len(v)
    v = v.lstrip(alphabet[0:1])
    newlen = len(v)

    acc = b58decode_int(v, alphabet=alphabet)

    result = []
    while acc > 0:
        acc, mod = divmod(acc, 256)
        result.append(mod)
    return b"\0" * (origlen - newlen) + bytes(reversed(result))
Enter fullscreen mode Exit fullscreen mode

save this file and this directory create file btc with any name.py .( my file name has " btcGeneratorWallet.py " ) and first import this package for project in first file :

import argparse
import hashlib
import os
from binascii import hexlify, unhexlify
from struct import Struct
from utils import g, b58encode, b58decode
import blockcypher
from moneywagon import AddressBalance
import requests
from urllib.request import urlopen
from urllib.request import Request
import satoshi
import re
Enter fullscreen mode Exit fullscreen mode

after import package can insert all code your file.py :


PACKER = Struct(">QQQQ")


def count_leading_zeroes(s):
    count = 0
    for c in s:
        if c == "\0":
            count += 1
        else:
            break
    return count


def base58_check_encode(prefix, payload, compressed=False):
    # Add version byte in front of RIPEMD-160 hash (0x00 for Main Network)
    s = prefix + payload
    if compressed:
        s = prefix + payload + b"\x01"
    # Add the 4 checksum bytes at the end of extended RIPEMD-160 hash. This is the 25-byte binary Bitcoin Address.
    checksum = hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4]
    result = s + checksum
    return "1" * count_leading_zeroes(result) + b58encode(result).decode()


def pub_key_to_addr(s):
    ripemd160 = hashlib.new("ripemd160")
    hash_sha256 = hashlib.new("SHA256")
    # Perform SHA-256 hashing on the public key
    hash_sha256.update(bytes.fromhex(s))
    # Perform RIPEMD-160 hashing on the result of SHA-256
    ripemd160.update(hash_sha256.digest())
    return base58_check_encode(b"\0", ripemd160.digest())


def btcwb(number):
    number0 = number >> 192
    number1 = (number >> 128) & 0xFFFFFFFFFFFFFFFF
    number2 = (number >> 64) & 0xFFFFFFFFFFFFFFFF
    number3 = number & 0xFFFFFFFFFFFFFFFF

    private_key = hexlify(PACKER.pack(number0, number1, number2, number3)).decode(
        "utf-8"
    )

    ###############################################
    print("Converting from: " + str(int(private_key, 16)))
    ###############################################

    compressed_key = base58_check_encode(b"\x80", unhexlify(private_key), True)

    ###############################################
    print("Private key    : " + compressed_key)
    ###############################################

    # address
    x, y = str(g * int(private_key, 16)).split()
    len1 = len(x)
    len2 = len(y)
    if len1 != 64:
        z = 64 - len1
        x = "0" * z + x
    if len2 != 64:
        z = 64 - len2
        y = "0" * z + y
    compressed_public_key_with_out_prefix = x + y
    pk_prefix = "02"
    if not int(compressed_public_key_with_out_prefix[64:], 16) % 2 == 0:
        pk_prefix = "03"
    compressed_public_key = pk_prefix + compressed_public_key_with_out_prefix[:64]

    ###############################################

    print("Public key     : " + compressed_public_key)
    print("Bitcoin address: " + pub_key_to_addr(compressed_public_key))
    with open("wallet.txt", "a") as f:
        f.write(
            "Converting from: "
            + str(int(private_key, 16))
            + "\nPrivate key: "
            + compressed_key
            + "\nPublic key: "
            + compressed_public_key
            + "\nBitcoin address: "
            + pub_key_to_addr(compressed_public_key)
            + "\n#####################################################################\n\n\n\n"
        )


def int_to_address(number):
    number0 = number >> 192
    number1 = (number >> 128) & 0xFFFFFFFFFFFFFFFF
    number2 = (number >> 64) & 0xFFFFFFFFFFFFFFFF
    number3 = number & 0xFFFFFFFFFFFFFFFF

    private_key = hexlify(PACKER.pack(number0, number1, number2, number3)).decode(
        "utf-8"
    )

    ###############################################
    print("Converting from: " + str(int(private_key, 16)))
    ###############################################

    compressed_key = base58_check_encode(b"\x80", unhexlify(private_key), True)

    ###############################################
    print("Private key    : " + compressed_key)
    ###############################################

    # address
    x, y = str(g * int(private_key, 16)).split()
    len1 = len(x)
    len2 = len(y)
    if len1 != 64:
        z = 64 - len1
        x = "0" * z + x
    if len2 != 64:
        z = 64 - len2
        y = "0" * z + y
    compressed_public_key_with_out_prefix = x + y
    pk_prefix = "02"
    if not int(compressed_public_key_with_out_prefix[64:], 16) % 2 == 0:
        pk_prefix = "03"
    compressed_public_key = pk_prefix + compressed_public_key_with_out_prefix[:64]

    ###############################################

    print("Public key     : " + compressed_public_key)
    ###############################################

    ###############################################
    print("Bitcoin address: " + pub_key_to_addr(compressed_public_key))
    try:
        total = blockcypher.get_total_balance(pub_key_to_addr(compressed_public_key))
    except:
        total = AddressBalance().action("btc", pub_key_to_addr(compressed_public_key))
    total_fiat = satoshi.to_fiat(int(total))
    # r = requests.get("https://blockchain.infor/rawaddr/{}".format(pub_key_to_addr(compressed_public_key)))
    tr = Request(
        "https://blockchain.info/q/getreceivedbyaddress/"
        + pub_key_to_addr(compressed_public_key)
    )
    total_received = str(urlopen(tr).read())
    trr = total_received[2:][:-1]
    total_fiat_received = satoshi.to_fiat(int(trr))

    ts = Request(
        "https://blockchain.info/q/getsentbyaddress/"
        + pub_key_to_addr(compressed_public_key)
    )
    total_sent = str(urlopen(ts).read())
    tsr = total_sent[2:][:-1]
    total_fiat_sent = satoshi.to_fiat(int(tsr))
    # print('$'+str(s))
    print("Total Sent     : " + str(tsr) + " || $" + str(total_fiat_sent))
    print("Total Received : " + str(trr) + " || $" + str(total_fiat_received))
    print("Final Balance  : " + str(total) + " || $" + str(total_fiat) + "\n")
    # stotal = blockcypher.from_satoshis(total, 'btc')
    with open("walletb.txt", "a") as f:
        f.write(
            "Converting from: "
            + str(int(private_key, 16))
            + "\nPrivate key: "
            + compressed_key
            + "\nPublic key: "
            + compressed_public_key
            + "\nBitcoin address: "
            + pub_key_to_addr(compressed_public_key)
            + "\nFianl Balance: "
            + str(total)
            + "\nTotal Received : "
            + str(trr)
            + " || $"
            + str(total_fiat_received)
            + "\nTotal Sent     : "
            + str(tsr)
            + " || $"
            + str(total_fiat_sent)
            + "\n#####################################################################\n\n\n\n"
        )
    if 0 < total:
        print(pub_key_to_addr(compressed_public_key) + " : " + total)
        with open("wallet_with_money.txt", "a") as m:
            m.write(
                "Converting from: "
                + str(int(private_key, 16))
                + "\nPrivate key: "
                + compressed_key
                + "\nPublic key: "
                + compressed_public_key
                + "\nBitcoin address: "
                + pub_key_to_addr(compressed_public_key)
                + "\nBitcoin Balance: "
                + str(total)
                + "\n#####################################################################\n\n\n\n"
            )
    else:
        pass
    ###############################################


def wif_to_key(wif):
    slicer = 4
    if wif[0] in ["K", "L"]:
        slicer = 5
    return hexlify(b58decode(wif)[1:-slicer]).decode("utf-8")


def main():
    try:
        os.system(r"cls")
    except:
        os.system(r"clear")
    print(
        """
 ____ _____ ____  __        __    _ _      _      ____                           _             
| __ )_   _/ ___| \ \      / /_ _| | | ___| |_   / ___| ___ _ __   ___ _ __ __ _| |_ ___  _ __ 
|  _ \ | || |      \ \ /\ / / _` | | |/ _ \ __| | |  _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \| '__|
| |_) || || |___    \ V  V / (_| | | |  __/ |_  | |_| |  __/ | | |  __/ | | (_| | || (_) | |   
|____/ |_| \____|    \_/\_/ \__,_|_|_|\___|\__|  \____|\___|_| |_|\___|_|  \__,_|\__\___/|_|  
    Author    : Mohammadreza (MMDRZA.COM)
    Github    : https://mmdrza.com                                                                                                                                                                                                    
[1] Generate a List of Wallets with a Range [with Balances]
[2] Generate a List of Wallets with a Range [without Balances]
[3] Guess a Number List to Generate a Wallet
'q' for quit
     """
    )

    x = input(">>> ")
    if x == "q":
        try:
            quit()
        except:
            exit()
    elif x == "1":
        r1 = int(input("Input Starting Range :> "))
        r2 = int(input("Input Ending Range   :> "))
        for x in range(r1, r2):
            int_to_address(x)
    elif x == "2":
        r1 = int(input("Input Starting Range :> "))
        r2 = int(input("Input Ending Range   :> "))
        for x in range(r1, r2):
            btcwb(x)
    elif x == "3":
        print("Enter your lucky number in the following format:")
        print("ex: 1 2 456 788 123 657 11 66 234 68 23\n")
        array = map(int, input("Enter Numbers by Keeping Space : ").split())
        for i in array:
            int_to_address(i)
            i += 1
    else:
        print("Command not Recognized")


main()
Enter fullscreen mode Exit fullscreen mode

for running this file and received result use this common in your terminal ( or cmd ) :

python btcGeneratorWallet.py ( this my file )
python <filename>.py

easy finder bitcoin private key wallet ( generator and finder )
can visit this site: https://key.config.ws for bitcoin wallet generator and keyword automatic finder free online .

Top comments (1)

Collapse
 
m3dedge profile image
M3d-Edge

i try to import private key didnt work why?