weil-reciprocity.sage 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. p = 115792089237316195423570985008687907853269984665640564039457584007908834671663
  2. Fp = GF(p)
  3. E = EllipticCurve(Fp, [0, 7])
  4. K.<x> = PolynomialRing(Fp, implementation="generic")
  5. L.<y> = PolynomialRing(K, implementation="generic")
  6. def call(f, P):
  7. Px, Py = P.xy()
  8. return f(x=Px, y=Py)
  9. def slope_intercept(P0, P1):
  10. P0x, P0y = P0.xy()
  11. P1x, P1y = P1.xy()
  12. m = (P1y - P0y) / (P1x - P0x)
  13. c = P1y - m*P1x
  14. return m, c
  15. inf = E(0, 1, 0)
  16. P0 = E(2638891549212558194816434702774699814912586136468438548683319413291233982670, 10140456388517236016202114238224306675726576846632714430386916682749918607464)
  17. P1 = E(17532914127565625088989484000002092349237591241902561765149751398626236254705, 88418181982451178952779569856811854926376929222674054022068577993668451054968)
  18. P2 = -(P0 + P1)
  19. assert P0 + P1 + P2 == inf
  20. m, c = slope_intercept(P0, P1)
  21. f = y - m*x - c
  22. assert call(f, P0) == 0
  23. assert call(f, P1) == 0
  24. assert call(f, P2) == 0
  25. A0 = E(71667150045698532747085079020221438975232032539323499361837608460679887058944, 112531462156938649599975140073878402074313288452223046891973447679626205036672)
  26. A1 = E(24400044380857008437858416414134907169391225728426050882076550827717815954208, 31119844425475844378953714282286295361574062544261840901985213408230446258932)
  27. A2 = -(A0 + A1)
  28. assert A0 + A1 + A2 == inf
  29. λ, μ = slope_intercept(A0, A1)
  30. g = y - λ*x - μ
  31. assert call(g, A0) == 0
  32. assert call(g, A1) == 0
  33. assert call(g, A2) == 0
  34. s = call(f, A0) * call(f, A1) * call(f, A2)
  35. t = call(g, P0) * call(g, P1) * call(g, P2)
  36. assert s == -t
  37. print(s)
  38. print(-t)