Elliptic curve arithmetic: Difference between revisions
Content added Content deleted
(→{{header|zkl}}: added code) |
m (→{{header|REXX}}: changed whitespace.) |
||
Line 1,217: | Line 1,217: | ||
<lang rexx>/*REXX program defines (for any 2 points on the curve), returns the sum of the 2 points.*/ |
<lang rexx>/*REXX program defines (for any 2 points on the curve), returns the sum of the 2 points.*/ |
||
numeric digits 100 /*try to ensure a min. of accuracy loss*/ |
numeric digits 100 /*try to ensure a min. of accuracy loss*/ |
||
a=func(1) |
a= func(1) ; say ' a = ' show(a) |
||
b=func(2) |
b= func(2) ; say ' b = ' show(b) |
||
c=add(a, b) |
c= add(a, b) ; say ' c = (a+b) =' show(c) |
||
d=neg(c) |
d= neg(c) ; say ' d = -c =' show(d) |
||
e=add(c, d) |
e= add(c, d) ; say ' e = (c+d) =' show(e) |
||
g=add(a, add(b, d)) |
g= add(a, add(b, d)) ; say ' g = (a+b+d) =' show(g) |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
Line 1,238: | Line 1,238: | ||
add: procedure; parse arg px py, qx qy; if px=qx & py=qy then return dbl(px py) |
add: procedure; parse arg px py, qx qy; if px=qx & py=qy then return dbl(px py) |
||
if isZ(px py) then return qx qy; if isZ(qx qy) then return px py |
if isZ(px py) then return qx qy; if isZ(qx qy) then return px py |
||
z=qx - px; |
z= qx - px; if z=0 then do; $= inf(); rx= inf(); end |
||
else do; $=(qy-py) / z; |
else do; $= (qy-py) / z; rx= $*$ - px - qx; end |
||
ry=$ * (px-rx) - py; |
ry= $ * (px-rx) - py; return rx ry |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
dbl: procedure; parse arg px py; if isZ(px py) then return px py; |
dbl: procedure; parse arg px py; if isZ(px py) then return px py; z= py+py |
||
if z=0 then $=inf() |
if z=0 then $= inf() |
||
else $=(3*px*py) / (py+py) |
else $= (3*px*py) / (py+py) |
||
rx=$*$ - px*px; ry=$ * (px-rx) - py; return rx ry |
rx= $*$ - px*px; ry= $ * (px-rx) - py; return rx ry |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
rootI: ox=x; oy=y; x=abs(x); y=abs(y); a=digits()+5; numeric form; g=rootG(); m=y-1 |
rootI: ox=x; oy=y; x=abs(x); y=abs(y); a=digits()+5; numeric form; g=rootG(); m=y-1 |