Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jack4818
GitHub Repository: jack4818/Castryck-Decru-SageMath
Path: blob/main/dead-code/FromJacToJac.sage
323 views
1
def FromJacToJac(h, D11, D12, D21, D22, a):
2
R.<x> = h.parent()
3
Fp2 = R.base()
4
5
J = Jacobian(HyperellipticCurve(h))
6
D1 = J(D11, D12)
7
D2 = J(D21, D22)
8
9
G1 = (2^(a-1)*D1)[0]
10
G2 = (2^(a-1)*D2)[0]
11
G3 = h / (G1*G2)
12
13
delta = Matrix(Fp2, 3, 3, [Coefficient(G1, 0), Coefficient(G1, 1), Coefficient(G1, 2),
14
Coefficient(G2, 0), Coefficient(G2, 1), Coefficient(G2, 2),
15
Coefficient(G3, 0), Coefficient(G3, 1), Coefficient(G3, 2)])
16
delta = delta.determinant()^(-1)
17
18
H1 = delta*(derivative(G2)*G3 - G2*derivative(G3))
19
H2 = delta*(derivative(G3)*G1 - G3*derivative(G1))
20
H3 = delta*(derivative(G1)*G2 - G1*derivative(G2))
21
22
hnew = H1*H2*H3
23
Jnew = Jacobian(HyperellipticCurve(hnew))
24
25
# now compute image points
26
# first the point [D11, D12]:
27
28
u0 = Coefficient(D11, 0)
29
u1 = Coefficient(D11, 1)
30
v0 = Coefficient(D12, 0)
31
v1 = Coefficient(D12, 1)
32
S.<x1,y1,y2,x2> = PolynomialRing(Fp2, 4)
33
# TODO: How is this computed in sage?
34
# pr = hom<S -> R | 0, 0, 0, x>
35
36
eq1 = x1^2 + u1*x1 + u0
37
eq2 = v1*x1 + v0 - y1
38
# TODO: What is evaluate doing?
39
# eq3 = Evaluate(G1, x1)*Evaluate(H1, x2) + Evaluate(G2, x1)*Evaluate(H2, x2)
40
# eq4 = y1*y2 - Evaluate(G1, x1)*Evaluate(H1, x2)*(x1 - x2)
41
# eq5 = y1^2 - Evaluate(h, x1)
42
43
I = Ideal([eq1, eq2, eq3, eq4, eq5])
44
G = GroebnerBasis(I) # last two are in non-reduced Mumford form: y2 + cubic(x2), quartic(x2)
45
# TODO what is pr?
46
# unew = pr(G[len(G)])
47
# vnew = -pr(G[len(G)-1])
48
# sanity check: (vnew^2 - hnew) mod unew
49
# TODO what is pr?
50
# imD1 = Jnew(pr(G[len(G)]), -pr(G[len(G)-1]))
51
52
# now same for the point [D21, D22]:
53
54
u0 = Coefficient(D21, 0)
55
u1 = Coefficient(D21, 1)
56
v0 = Coefficient(D22, 0)
57
v1 = Coefficient(D22, 1)
58
eq1 = x1^2 + u1*x1 + u0
59
eq2 = v1*x1 + v0 - y1
60
I = Ideal([eq1, eq2, eq3, eq4, eq5])
61
G = GroebnerBasis(I)
62
# TODO what is pr?
63
# unew = pr(G[len(G)])
64
# vnew = -pr(G[len(G)-1])
65
# TODO what is pr?
66
# imD2 = Jnew(pr(G[len(G)]), -pr(G[len(G)-1]))
67
68
return hnew, imD1[0], imD1[1], imD2[0], imD2[1]
69