Point doubling code

asked 2017-12-13 23:28:13 -0500

anonymous user

Anonymous

The below code is for point doubling arithmetic of elliptic curve but it is got stuck when i run the code on SAGE math cloud due to gcd operation #point Doubling import time p =2^192-2^64-1;#p A=6277101735386680763835789423207666416102355444464034512892 B=2455155546008943817740293915197451784769108058161191238065 print"\n p=",p print"\n A=",A print"\n B=",B

F = GF(p , proof=False) E = EllipticCurve( F, [A,B] );

S. = PolynomialRing( F ) K. = GF( p^2);#K.modulus#, modulus=W^2+W+1 ) print "\n Modulus of K is =", K.modulus()

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 + (4184734490257787175890526282138444277383123552235646790315a + 2092367245128893587945263141069222138682338404080968619351)z^6277101735386680763835789423207666416083908700390324961279 + (5579645987010382901187368376184592369852363289235844410026a + 2789822993505191450593684188092296184926181644617922205013)z^3 + 4184734490257787175890526282138444277389272466926883307519z^2 + (2092367245128893587945263141069222138700785148154678170964a + 4184734490257787175890526282138444277383123552235646790315)*z + 3821946189377736946095495508010214631314800642229133723214

print "\n Elliptic Curve fE(z) = ", f

P = E.random_point()

Q = E.random_point()

print "\n point1 =", P.xy()

print "\n point2 =", Q.xy()

start1 = time.time() H = P + P; end1 = time.time() Hx, Hy = H.xy() print "\n H = P + P has the components:\nHx = %s\nHy = %s" % ( Hx, Hy ) print "\n Time for this operation (existing approach): %s" % ( end1 - start1 )

start = time.time() g = ((2P[1]y)-((3P[0]^2)+A)x -(-P[0]^3+(AP[0])+2B))

g = ( ( 2 * P[1] * y ) - ( ( 3 * P[0]^2) + A) * x

 #-(-P[0]^3 + ( A * P[0] ) + 2 * B) )

print "\n Line equation =", g

f1 = gcd( f , g )#.monic() print "\n f1 = gcd (fE,fL) = ", f1

f2 = ( z - P[0] - P[1]a ) # ( z - Q[0] - Q[1]*a ) print "\n point equation =", f2

f3 = f1 // f2 print "\n Division of two polynomials f1 & f2 =", f3

c = f3.constant_coefficient() f4=(-c) M0, M1 = S(f4).coefficients()

G = E.point( ( M0, -M1 ) ) end = time.time()

Gx, Gy = G.xy() print "\n G = P + Q has the components:\nGx = %s\nGy = %s" % ( Gx, Gy ) print "\n Time for this operation (new approach): %s" % ( end - start )code here

edit retag flag offensive close merge delete

Comments

Welcome to Ask Sage! Thanks for your question!

slelievre gravatar imageslelievre ( 2017-12-14 03:08:19 -0500 )edit

To display inline code, like f, use backticks.

To display blocks of code or error messages, separate them by a blank line from the rest of the text, and do one of the following (all give the same result):

  • indent all code lines with 4 spaces
  • select code lines and click the "code" button (the icon with '101 010')
  • select code lines and hit ctrl-K

For instance, typing

If we define `f` by

    def f(x, y):
        return (x, y)

then `f(2, 3)` returns `(2, 3)` but `f(2)` gives:

    TypeError: f() takes exactly 2 arguments (1 given)

produces:

If we define f by

def f(x, y):
    return (x, y)

then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)

Please edit your question to do that.

slelievre gravatar imageslelievre ( 2017-12-14 03:08:24 -0500 )edit

This question is related to

question/39554

Please mention this in such cases, this is fair and makes potential answerers save time. (Not doing this is not fair.)

Please be so kind and give more mathematical details.

  • What is $f$?
  • Is this question related to completely new, own research, or a try to understand an always published structure. In both cases it is fair to mention the source (for the background, respectively for the already existing publication).

Also, as in loc. cit., why is coming the question without structure?

Why not give simple code for $x,y$?

Please do not post anonymously in such situations.

dan_fulea gravatar imagedan_fulea ( 2017-12-14 18:15:37 -0500 )edit