point_addition_affine_short_weierstrass.txt 1.25 KB
Newer Older
Aaisha Ghodekar's avatar
Aaisha Ghodekar committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def Pointaddition_affine(x1,x2,y1,y2,a,PRECISION):

x1_poly= str_to_poly(x1)
y1_poly=str_to_poly(y1)
x2_poly= str_to_poly(x2)
y2_poly=str_to_poly(y2)


print 'x1_poly=',x1_poly
print 'y1_poly=',y1_poly

print 'x2_poly=',x2_poly
print 'y2_poly=',y2_poly

xpoly = (1)
	expp = 2^PRECISION-2
	for i in reversed(xrange(PRECISION)):
			xpoly = xpoly * xpoly
			if(expp.digits(base = 2,padto=PRECISION)[i] == 1):
					xpoly = x1_poly* xpoly
	inv_x1_poly = xpoly
xpoly = (2)
	expp = 2^PRECISION-2
	for i in reversed(xrange(PRECISION)):
			xpoly = xpoly * xpoly
			if(expp.digits(base = 2,padto=PRECISION)[i] == 1):
					xpoly = x2_poly* xpoly
	inv_x2_poly = xpoly

#Calculation of resultant coordinates
x3_poly = ( (y1_poly + y2_poly) *(inv_x1_poly + inv_x2_poly) ) ** 2 + ( (y1_poly + y2_poly) * (inv_x1_poly + inv_x2_poly) ) + x1_poly + x2_poly + a

y3_poly = ( (y1_poly + y2_poly) *(inv_x1_poly + inv_x2_poly) ) ** 3 + (x2_poly + a + 1 ) * (y1_poly +  y2_poly *(inv_x1_poly + inv_x2_poly) ) + x1_poly + x2_poly + a + y1_poly

print 'x3=',poly_to_str(x3_poly)
print 'y3=',poly_to_str(y3_poly)

 #Affine addition formulas: 
 #(x1,y1)+(x2,y2)=(x3,y3) 
    
 #where
     # x3 = ((y1+y2)/(x1+x2))2+((y1+y2)/(x1+x2))+x1+x2+a2
     # y3 = ((y1+y2)/(x1+x2))3+(x2+a2+1)*((y1+y2)/(x1+x2))+x1+x2+a2+y1