For me, the key video explaining the math for bitcoin elliptic curve secp256k1 was this: Bitcoin 101 - Elliptic Curve Cryptography - Part 4 - Generating the Public Key (in Python)
And if you want to check with a python script I extracted from the video, you can use this:
#!/usr/bin/python3
# Super simple Elliptic Curve Presentation. No imported libraries, wrappers, nothing.
# For educational purposes only.
# Below are the public specs for Bitcoin's curve - the secp256k1
# webs for checking
# https://www.bitaddress.org/bitaddress.org-v3.3.0-SHA256-dec17c07685e1870960903d8f58090475b25af946fe95a734f88408cef4aa194.html
# https://www.mobilefish.com/services/cryptocurrency/cryptocurrency.html
# datos para usar la curva secp256k1
Pcurve = 2 ** 256 - 2 ** 32 - 2 ** 9 - 2 ** 8 - 2 ** 7 - 2 ** 6 - 2 ** 4 - 1 # The proven prime
N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 # Number of points in the field
Acurve = 0
Bcurve = 7 # These two defines the elliptic curve. y^2 = x^3 + Acurve * x + Bcurve
Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
GPoint = (Gx, Gy) # This is our generator point. Trillions of dif ones possible
# Individual Transaction/Personal Information
privKey = 0x0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
def modinv(a: int, n: int = Pcurve): # MAXIMO COMUN DIVISOR: Extended Euclidean Algorithm/'division' in elliptic curves
lm, hm = 1, 0
resto = a % n
high = n
while resto > 1:
ratio = high // resto
nm = hm - lm * ratio
new = high - resto * ratio
lm, resto, hm, high = nm, new, lm, resto
return lm % n
def ECadd(a, b): # Not true addition, invented for EC. Could have been called anything.
LamAdd = ((b[1] - a[1]) * modinv(b[0] - a[0], Pcurve)) % Pcurve
x = (LamAdd * LamAdd - a[0] - b[0]) % Pcurve
y = (LamAdd * (a[0] - x) - a[1]) % Pcurve
return x, y
def ECdouble(a): # This is called point doubling, also invented for EC.
Lam = ((3 * a[0] * a[0] + Acurve) * modinv((2 * a[1]), Pcurve)) % Pcurve
x = (Lam * Lam - 2 * a[0]) % Pcurve
y = (Lam * (a[0] - x) - a[1]) % Pcurve
return x, y
def EccMultiply(gen_point: tuple, scalar_hex: int): # Double & add. Not true multiplication
if scalar_hex == 0 or scalar_hex >= N:
raise Exception("Invalid Scalar/Private Key")
ScalarBin = str(bin(scalar_hex))[2:] # string binario sin el comienzo 0b
Q = gen_point # esto es una tupla de dos integer del punto de generacion de la curva
for i in range(1, len(ScalarBin)):
Q = ECdouble(Q)
if ScalarBin[i] == "1":
Q = ECadd(Q, gen_point) #
return Q
print("******* Public Key Generation *********")
print()
PublicKey = EccMultiply(GPoint, privKey)
print("the private key:")
print(privKey)
print()
print("the uncompressed public key (not address):")
print(PublicKey)
print()
x = hex(PublicKey[0])[2:].upper()
y = hex(PublicKey[1])[2:].upper()
print(f"The x: {x}")
print(f"The y: {y}")
print()
print("the uncompressed public key (HEX):")
pub_uncomp = f"04{hex(PublicKey[0])[2:].upper()}{hex(PublicKey[1])[2:].upper()}"
print(pub_uncomp)
print()
print("the official Public Key - compressed:")
if PublicKey[1] % 2 == 1: # If the Y value for the Public Key is odd.
print("03" + str(hex(PublicKey[0])[2:]).zfill(64).upper())
else: # Or else, if the Y value is even.
print("02" + str(hex(PublicKey[0])[2:]).zfill(64).upper())
Lastly you can see how to get the whole process, including WIF format and public addresses, check this.