#[0] please convert below ruby code to python # y² = x³ + ax + b

$a = 0

$b = 7

# prime field

$p = 2 ** 256 - 2 ** 32 - 2 ** 9 - 2 ** 8 - 2 ** 7 - 2 ** 6 - 2 ** 4 - 1

# number of points on the curve we can hit ("order")

$n = 115792089237316195423570985008687907852837564279074904382605163141518161494337

# generator point (the starting point on the curve used for all calculations)

$G = {

x: 55066263022277343669578718895168534326250603453777594175500187360389116729240,

y: 32670510020758816978083085130507043184471273380659243275938904335757337482424,

}

Reply to this note

Please Login to reply.

Discussion

a = 0

b = 7

p = 2 ** 256 - 2 ** 32 - 2 ** 9 - 2 ** 8 - 2 ** 7 - 2 ** 6 - 2 ** 4 - 1

n = 115792089237316195423570985008687907852837564279074904382605163141518161494337

G = {

"x": 55066263022277343669578718895168534326250603453777594175500187360389116729240,

"y": 32670510020758816978083085130507043184471273380659243275938904335757337482424,

}

#[0] covert below ruby to to python def double(point)

# slope = (3x₁² + a) / 2y₁

slope = ((3 * point[:x] ** 2 + $a) * inverse((2 * point[:y]), $p)) % $p # using inverse to help with division

# x = slope² - 2x₁

x = (slope ** 2 - (2 * point[:x])) % $p

# y = slope * (x₁ - x) - y₁

y = (slope * (point[:x] - x) - point[:y]) % $p

# Return the new point

return { x: x, y: y }

end