# scalar multiplication Anonymous

kindly help me to run the below code in sage math cloud to obtained scalar multiplication Q

E = EllipticCurve(GF(71),[41,18] ) p = E(63,32) k=2 def mult(P,k): if k == 0: return E(0) elif k%2 ==1: return P + mult(P+P,k//2) else: return mult(P+P,k//2)

edit retag close merge delete

Please learn how to insert code on this site.

Note that some python code has a different meaning in the markup language of this site.

The following should work. Type the text. When a block code starts, then:

• type a new line
• copy and paste the code
• as long as it stays marked press Control+K, this will indent the code with 4 spaces, finally it will be shown as code on the site.
• type one more new line to declare the code block was done.

Please do not post anonymously any longer.

Sort by » oldest newest most voted

The following works for me in the sage interpreter:

E = EllipticCurve( GF(71), [41, 18] )
p = E( 63, 32 )
k = 2

def mult(P, k):
if k == 0:
return E(0)
elif k<0:
return -mult(P, -k)
elif k%2 == 1:
return P + mult(P+P, k//2)
else:
return mult(P+P, k//2)


Test:

sage: mult(p, k)
(43 : 63 : 1)
sage: k*p
(43 : 63 : 1)
sage: mult(p, 2017)
(27 : 54 : 1)
sage: 2017*p
(27 : 54 : 1)
sage: mult(p, 2018)
(0 : 36 : 1)
sage: 2018*p
(0 : 36 : 1)
sage: mult(p, -2017)
(27 : 17 : 1)
sage: (-2017)*p
(27 : 17 : 1)

more