Created
November 3, 2025 05:42
-
-
Save MurageKibicho/e9d44431735d7af1afe0d9c282abc589 to your computer and use it in GitHub Desktop.
Pell Curve Finite Field Group Structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Self-contained Python script for Pell conic group law check | |
| def pell_add(a, b, D, p): | |
| """Group law on x^2 - D*y^2 = 1 mod p.""" | |
| x1, y1 = a | |
| x2, y2 = b | |
| x3 = (x1 * x2 + D * y1 * y2) % p | |
| y3 = (x1 * y2 + x2 * y1) % p | |
| return x3, y3 | |
| def pell_check(point, D, p): | |
| """Verify that point satisfies x^2 - D*y^2 ≡ 1 mod p.""" | |
| x, y = point | |
| lhs = (x*x - D*y*y) % p | |
| return lhs == 1 % p | |
| if __name__ == "__main__": | |
| # Parameters | |
| D = 16991 | |
| p = 20959 | |
| P = (2611, 15590) | |
| invP = (P[0], (-P[1]) % p) | |
| Q = invP | |
| print("Inverse of P:", invP) | |
| # Check the point is on the curve | |
| print("Checking that P is on the Pell conic:") | |
| print("Valid point:", pell_check(P, D, p)) | |
| # Double the point | |
| P2 = pell_add(P, Q, D, p) | |
| print("\nP + Q =", P2) | |
| # Check if result is identity (1, 0) | |
| print("\nIs P+P the identity (1,0)?", P2 == (1, 0)) | |
| # Verify it also lies on the conic | |
| print("P+P on the conic:", pell_check(P2, D, p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment