Ask Your Question
0

scalar multiplication

asked 2017-12-15 07:03:07 +0100

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 09:49:17 +0100 )edit

thank you madam/sir fpr your advise

santoshi gravatar imagesantoshi ( 2017-12-15 18:07:45 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-12-15 09:58:19 +0100

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 07:03:07 +0100

Seen: 153 times

Last updated: Dec 15 '17