You are on page 1of 3

CRYPTOGRAPHY FUNDAMENTALS LAB ASSIGNMENT

NAME: GOKUL LEBURU


REG NO: 18BCI0093

AIM: TO IMPLEMENT THE ECC-POINT ADDITION AND


MULTIPLICATION

ALGORITHM:

ELLIPTIC CURVE : y 2 = x 3 + ax + b

ADDITION:

(x1, y1) + (x2, y2) = (x3, y3)

IF x1 != x2;

λ = (y2 − y1)(x2 − x1) −1

IF X1=X2:

λ = (3x 2 1 + a)(2y1) −1

x3 = λ 2 − x1 − x2

y3 = λ(x1 − x3) − y1

MULTIPLICATION:
if(sc>=2):
for i in range(0,sc-1):
xrr,yrr=pointAdd(xpp,ypp,xrr,yrr)

CODE:
def modInverse(ai,m):
ai=ai%m
for x in range(1,m):
if((ai*x)%m==1):
return x
return 1
def pointAdd(xpp,ypp,xqq,yqq):
if((xpp==xqq) and (ypp==yqq)):
lam=((3*(xpp**2)+a)*(modInverse(2*ypp,p)))%p
else:
lam=((ypp-yqq)*(modInverse(xpp-xqq,p)))%p
xrr=((lam**2)-xpp-xqq)%p
yrr=((lam*(xpp-xrr))-ypp)%p
return xrr,yrr
def pointMul(xpp,ypp,sc):
xrr=xpp
yrr=ypp
if(sc>=2):
for i in range(0,sc-1):
xrr,yrr=pointAdd(xpp,ypp,xrr,yrr)
return xrr,yrr
#INPUT STATEMENTS:
p=int(input("Enter the modulus value: "))
a=int(input("Enter the co-efficient 'a': "))
b=int(input("Enter the co-efficient 'b': "))
xp=int(input("Enter the x-coordinate of the first point: "))
yp=int(input("Enter the y-coordinate of the first point: "))
xq=int(input("Enter the x-coordinate of the second point: "))
yq=int(input("Enter the y-coordinate of the second point: "))
#POINT ADDITION:
xr,yr=pointAdd(xp,yp,xq,yq)
print("The sum is: p = (",xr,",",yr,") ")
#POINT MULTIPLICATION:
sca=int(input("Enter the scalar value: "))
xr,yr=pointMul(xp,yp,sca)
print("The product of ",sca,"p: (",xr,",",yr,") ")
OUTPUT:

You might also like