Skip to content

Instantly share code, notes, and snippets.

@amadhurkant
amadhurkant / isogeny_test.sage
Created July 21, 2025 06:33
Isogeny of elliptic curve demonstration using sagemath.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~ Construction of an Isogeny Between Elliptic Curves ~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Field and Curve Definitions
p = 97
F = GF(p)
E1 = EllipticCurve(F, [1, 24])
E2 = EllipticCurve(F, [42, 46])
@amadhurkant
amadhurkant / modroots.py
Last active July 21, 2025 06:47
Python calculate modular roots using libnum and tonelli-shanks
import libnum
from typing import List, Optional
def modular_square_roots(a: int, p: int) -> Optional[List[int]]:
"""Return all x such that x² ≡ a (mod p), or None if none exist."""
if not libnum.has_sqrtmod_prime_power(a, p):
return None
return list(libnum.sqrtmod_prime_power(a, p))