Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Node.js Online

		function mul(a, b, p)
		{
			return (a*b)%p
		}
		function div(a, b, p)
		{
			while(a < 0)
				a += p

			while(b < 0)
				b += p

			for(var i = 0; i<p; ++i)
				if(mul(i, b, p) == a)
					return i
		}
		function EllipticCurve(a, b, p)
		{
			return {
				a: a % p,
				b: b % p,
				p: p
			}
		}
		function PointOnEllipticCcurve(curve, x, y)
		{
			return (x*x*x + curve.a*x + curve.b - y*y) % curve.p == 0
		}
		function EllipticCurvePoints(curve)
		{
			var points = []

			for(var i=0; i<curve.p; ++i)
				for(var j=0; j<curve.p; ++j)
					if(PointOnEllipticCurve(curve, i, j))
						points.push({x: i, y: j})

			return points
		}
		function AddEllipticPoint(curve, p1, p2)
		{
			var s

			if(p1.is_null)
				return p2

			if(p2.is_null)
				return p1
			if(p1.x != p2.x)
			{
				s = div(p1.y - p2.y, p1.x - p2.x, curve.p)
				var p_x = (s*s - p1.x -p2.x) % curve.p

				return {
					x: p_x,
					y: (-p1.y + s*(p1.x - p_x)) % curve.p
				} 
			}
			if(p1.y == p2.y)
			{
				s = div((3 * p1.x*p1.x + curve.a)%curve.p, 2*p1.y % curve.p, curve.p)
				var p_x = (s*s - 2*p1.x) % curve.p
				return {
					x: p_x,
					y: (-p1.y + s*(p1.x - p_x))%curve.p
				}
			}
			return {
				x:       0,
				y:       0,
				is_null: true
			}
		}
		function NormalizePoint(curve, p)
		{
			while(p.x < 0)
				p.x += curve.p

			while(p.y < 0)
				p.y += curve.p

			return p
		}
		var curve = EllipticCurve(-1, 188, 751)
		function nP(curve, point, n)
		{
			var p1 = {x: point.x, y: point.y}
			var p2 = {x: point.x, y: point.y}

			for(var i=0; i<n - 1; ++i)
			{
				p1 = AddEllipticPoint(curve, p1, p2)
				NormalizePoint(curve, p1)
			}
			return p1
		}
		
		console.log( nP(curve, {x: 0, y: 250}, 260))
		

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.