Ask Your Question
0

scalar multiplication

asked 2017-12-15 00:03:07 -0500

anonymous user

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 flag offensive close merge delete

Comments

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.

dan_fulea gravatar imagedan_fulea ( 2017-12-15 02:49:17 -0500 )edit

thank you madam/sir fpr your advise

santoshi gravatar imagesantoshi ( 2017-12-15 11:07:45 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-15 02:58:19 -0500

dan_fulea gravatar image

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-12-15 00:03:07 -0500

Seen: 18 times

Last updated: Dec 15 '17