Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: the fastest possible way to mass-generate addresses in Python
by
nomachine
on 28/09/2023, 04:40:42 UTC
⭐ Merited by digaran (1)

I was looking only for public key generation part



Here's a simplified script that generates compressed public keys from a given range of private keys:

Code:
import hashlib

# Define constants
N = int("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16)
Gx = int("55066263022277343669578718895168534326250603453777594175500187360389116729240")
Gy = int("32670510020758816978083085130507043184471273380659243275938904335757337482424")

def modinv(a, n):
    lm, hm = 1, 0
    low, high = a % n, n
    while low > 1:
        ratio = high // low
        nm, new = hm - lm * ratio, high - low * ratio
        lm, low, hm, high = nm, new, lm, low
    return lm % n

def ECadd(a, b, p):
    lam_add = ((b[1] - a[1]) * modinv(b[0] - a[0], p)) % p
    x = (lam_add * lam_add - a[0] - b[0]) % p
    y = (lam_add * (a[0] - x) - a[1]) % p
    return x, y

def ECdouble(a, p):
    lam = ((3 * a[0] * a[0]) * modinv((2 * a[1]), p)) % p
    x = (lam * lam - 2 * a[0]) % p
    y = (lam * (a[0] - x) - a[1]) % p
    return x, y

def EccMultiply(gen_point, scalar_hex, p):
    Q = gen_point
    for bit in reversed(format(scalar_hex, 'b')):
        if bit == '1':
            Q = ECadd(Q, gen_point, p)
        gen_point = ECdouble(gen_point, p)
    return Q

def private_to_compressed_public(hex_private_key):
    private_key = int(hex_private_key, 16)
    public_key = EccMultiply((Gx, Gy), private_key, N)
   
    if public_key[1] % 2 == 1:
        prefix = '03'
    else:
        prefix = '02'
   
    compressed_public_key = prefix + format(public_key[0], '064x')
    return compressed_public_key

if __name__ == "__main__":
    start_range = int("D2C55", 16)
    end_range = int("1BA534", 16)
   
    for private_key in range(start_range, end_range + 1):
        hex_private_key = format(private_key, 'x')
        compressed_public_key = private_to_compressed_public(hex_private_key)
        print(f"Private Key: {hex_private_key}")
        print(f"Compressed Public Key: {compressed_public_key}")


Mobile phones typically run Android or iOS. Python can be run on both platforms, but there are some differences.
For Android, you can use the QPython app or Termux to run Python scripts. On iOS, you might need to use apps like Pythonista or Pyto.
It may require a lot of CPU power and memory. Make sure your mobile phone can handle the computational requirements.
You can evan translate this script into a mobile app  but I don't see the purpose of it on the phone. Neither the script will work as it should nor the phone.