# Revision history [back]

### error in elliptic curve scalar multiplication code

The following code i have written for scalar multiplication over elliptic curve for prime field 37 but it gives me error for some of the scalar. the method is LSB first.enter code here
import time import sys from sage.all import *

# domain parameters

p=37 A=7 B=25 G=1 n=21

print"\n p=",p print"\n A=",A print"\n B=",B F=GF(p)

E = EllipticCurve( F, [A,B] ); print "\n Elliptic curve equation=", E

x1 = P[0]
y1 = P[1]
x2 = Q[0]
y2 = Q[1]

# check P == O
if P == [0, 0]:
return Q

# check Q == O
if Q == [0, 0]:
return P

# check Q == -P
if x1 == x2 and y1 + y2 == 0:
return [0, 0]

# check P == Q
if P == Q:
return point_double(P)
slope = F((y2 - y1)/(x2 - x1))
x3 = F(slope**2 - x1 - x2)
y3 = F(slope * (x1 - x3) - y1)

return[x3 , y3]

def point_double(P):

#if P == [0, 0]:
#return [0, 0]

x1 = P[0]
y1 = P[1]

slope = F((3 * x1**2 + A)/(2 * y1))
x3 = F(slope**2 - 2 * x1)
y3 = F(slope * (x1 - x3) - y1)
return [x3, y3]

def scalar_mult(K,P): print('hi') b_k =ZZ(K).bits();print(b_k); #K.digits(2); l = len(b_k);l sum1 = 0*P;sum1 print(b_k[0]) if b_k[0] == 1: sum1 = P;sum1 else: sum1 = 0 Q = P;print(Q) for i in range(1,l): Q = point_double(Q);print(Q) if b_k[i] == 1: print (b_k[i]) #sum = point_add(sum,Q) sum1 = point_add(sum1,Q) print(sum1)#Q = point_double(Q);

return sum1

 2 None slelievre 10168 ●8 ●107 ●203 http://carva.org/samue...

### error in elliptic curve scalar multiplication code

The following code i have written for scalar multiplication over elliptic curve for prime field 37 but it gives me error for some of the scalar. the method is LSB first.

enter code here
import time import sys from sage.all import *

# prime192v1 # domain parameters

p=37 A=7 B=25 G=1 n=21

print"\n p=",p print"\n A=",A print"\n B=",B F=GF(p)

parameters p = 37 A = 7 B = 25 G = 1 n = 21 print "\n p =", p print "\n A =", A print "\n B =", B F = GF(p) E = EllipticCurve( F, [A,B] ); EllipticCurve(F, [A,B]) print "\n Elliptic curve equation=", E

Q):

x1 = P[0]
y1 = P[1]
x2 = Q[0]
y2 = Q[1]

# check P == O
if P == [0, 0]:
return Q

# check Q == O
if Q == [0, 0]:
return P

# check Q == -P
if x1 == x2 and y1 + y2 == 0:
return [0, 0]

# check P == Q
if P == Q:
return point_double(P)
slope = F((y2 - y1)/(x2 - x1))
x3 = F(slope**2 - x1 - x2)
y3 = F(slope * (x1 - x3) - y1)

return[x3 ,     return[x3, y3]

def point_double(P):

#if point_double(P):

# if P == [0, 0]:
#return #     return [0, 0]

x1 = P[0]
y1 = P[1]

slope = F((3 * x1**2 + A)/(2 * y1))
x3 = F(slope**2 - 2 * x1)
y3 = F(slope * (x1 - x3) - y1)
return [x3, y3]

def scalar_mult(K,P): print('hi') b_k =ZZ(K).bits();print(b_k); #K.digits(2); = ZZ(K).bits(); print(b_k) # ; K.digits(2) l = len(b_k);l len(b_k); l sum1 = 0*P;sum1 0*P; sum1 print(b_k[0]) if b_k[0] == 1: sum1 = P;sum1 P; sum1 else: sum1 = 0 Q = P;print(Q) P; print(Q) for i in range(1,l): range(1, l): Q = point_double(Q);print(Q) point_double(Q); print(Q) if b_k[i] == 1: print (b_k[i]) #sum = point_add(sum,Q) (b_k[i]) # sum = point_add(sum, Q) sum1 = point_add(sum1,Q) print(sum1)#Q = point_double(Q);