OverflowError: Python int too large to convert to C long [closed]

asked 2017-11-15 07:31:24 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

import time
p=2^192-2^64-1 A=-3#4451685225093714772084598273548424 B=1#2455155546008943817740293915197451784769108058161191238065 K.=GF(p^2);K.modulus()

R.<z>=PolynomialRing(K);

R.<z> = PolynomialRing( K, sparse=True ) x= (2092367245128893587945263141069222138694636233463441653760a + 4184734490257787175890526282138444277389272466926883307520)z^6277101735386680763835789423207666416083908700390324961279 + (4184734490257787175890526282138444277389272466926883307519a + 2092367245128893587945263141069222138694636233463441653760)z

y= (4184734490257787175890526282138444277389272466926883307520a + 2092367245128893587945263141069222138694636233463441653760)z^6277101735386680763835789423207666416083908700390324961279 + (2092367245128893587945263141069222138694636233463441653759a + 4184734490257787175890526282138444277389272466926883307519)z

f=(697455748376297862648421047023074046231545411154480551253a + 3487278741881489313242105235115370231157727055772402756266)z^18831305206160042291507368269622999248251726101170974883837 + (4184734490257787175890526282138444277389272466926883307519a + 2092367245128893587945263141069222138694636233463441653759)z^12554203470773361527671578846415332832167817400780649922559 + 4184734490257787175890526282138444277389272466926883307519z^12554203470773361527671578846415332832167817400780649922558 + (2092367245128893587945263141069222138694636233463441653760a + 4184734490257787175890526282138444277389272466926883307519)z^6277101735386680763835789423207666416083908700390324961281 + 4184734490257787175890526282138444277389272466926883307520z^6277101735386680763835789423207666416083908700390324961280 + (a + 2)z^6277101735386680763835789423207666416083908700390324961279 + (5579645987010382901187368376184592369852363289235844410026a + 2789822993505191450593684188092296184926181644617922205013)z^3 + 4184734490257787175890526282138444277389272466926883307519z^2 + (6277101735386680763835789423207666416083908700390324961278a + 1)z + 627710173538668076383578942320766641608390870039032496127 print"\n Elliptic Curve fE(z) = ",f

fE11 = fE.coefficients();fE11

start = time.time()

E = EllipticCurve(GF(p),[0,0,0,A,B]);

print"EC=",E

print (E.points()[:4])

print "\n Take Two point on Elliptic curve "

P = E.random_point()#[2];E(0,2) print"\n point1=",P # select Random point P on elliptic Curve
Q =E.random_point()#[4]; E(4,2) print"\n point2=",Q

P= E(59708,90244);P

Q= E(108685,5812);Q

R1=P+Q; print"\n Addition of two points Existing Approach (P+Q) =",R1

if((P[0]!=Q[0]) and (P[1]!=Q[1]) or (P[0]!=Q[0]) and (P[1]==Q[1])): g=(((Q[0]-P[0])y)-((Q[1]-P[1])x)-(P[1]Q[0]-Q[1]P[0])) ;Error obtained at this line g3=g-g1-g2; print"\n g3=",g3 f1=( f % g ).monic() print "\n gcd=",f1 #R2=fL.quo_rem(f1);R2 #R3=fE.quo_rem(f1);R3 f2= (z-P[0]-P[1]a)(z-Q[0]-Q[1]a); print "\n point equation=",f2 f3=f1//f2; print "\n f3=",f3; new4 = f3.coefficients();new4 Result=new4[0];Result #R15=K(-Result);R15 F.=GF(p) R.=PolynomialRing(F); R1.<z>=PolynomialRing(R); f=Result M=R(f).coefficients();#M M1= M[1];#M1 M4=M[0];#M4 M2=F(-M4);#M2 M3=F(-M4) R=(M2a+M[1]);#R R1=(M2,M1);#R1 #load("example.sage") G = E.point((R1));#G print "\n Addition of two points New Approach(P+Q)=" ,G
end = time.time() print("the time taken for the existing approach is given by ", end - start)

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by tmonteil
close date 2017-11-15 09:56:53.460194