Skip to content

Instantly share code, notes, and snippets.

@bjarnemagnussen
Created May 9, 2020 15:46
Show Gist options
  • Save bjarnemagnussen/7c9d6d7724fc421f6db6c11d97d15db6 to your computer and use it in GitHub Desktop.
Save bjarnemagnussen/7c9d6d7724fc421f6db6c11d97d15db6 to your computer and use it in GitHub Desktop.
from collections import namedtuple
FIELD_SIZE = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f
GROUP_ORDER = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
TONELLI_SHANKS_CONSTANT = (FIELD_SIZE + 1) // 4
BASE_POINT_PARAMETERS = (
0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,
0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
)
Point = namedtuple('Point', ('x', 'y'))
def parity(num):
return num & 1
def x_to_y(x, y_parity):
y = pow(x ** 3 + 7, TONELLI_SHANKS_CONSTANT, FIELD_SIZE)
if parity(y) != y_parity:
y = FIELD_SIZE - y
return y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment