diff --git a/Calculators/Elliptic Curve Calculator/README.md b/Calculators/Elliptic Curve Calculator/README.md new file mode 100644 index 000000000..7e6798652 --- /dev/null +++ b/Calculators/Elliptic Curve Calculator/README.md @@ -0,0 +1,23 @@ +#

Air Quality Index Calculator

+ +## Description :- + +Calculates the following things for an elliptic curve:- + +1. Addition of 2 points +2. Negation of a point +3. Multiplication of a point with a scalar +4. All points on the curve + +## Tech Stacks :- + +- HTML +- CSS +- JavaScript + +## Screenshots :- + +![1726495279660](image/readme/1726495279660.png) +![1726495391951](image/readme/1726495391951.png) +![1726495418726](image/readme/1726495418726.png) +![1726495436282](image/readme/1726495436282.png) diff --git a/Calculators/Elliptic Curve Calculator/image/readme/1726495279660.png b/Calculators/Elliptic Curve Calculator/image/readme/1726495279660.png new file mode 100644 index 000000000..3770f0c1f Binary files /dev/null and b/Calculators/Elliptic Curve Calculator/image/readme/1726495279660.png differ diff --git a/Calculators/Elliptic Curve Calculator/image/readme/1726495391951.png b/Calculators/Elliptic Curve Calculator/image/readme/1726495391951.png new file mode 100644 index 000000000..ab98e7aba Binary files /dev/null and b/Calculators/Elliptic Curve Calculator/image/readme/1726495391951.png differ diff --git a/Calculators/Elliptic Curve Calculator/image/readme/1726495418726.png b/Calculators/Elliptic Curve Calculator/image/readme/1726495418726.png new file mode 100644 index 000000000..9344501cf Binary files /dev/null and b/Calculators/Elliptic Curve Calculator/image/readme/1726495418726.png differ diff --git a/Calculators/Elliptic Curve Calculator/image/readme/1726495436282.png b/Calculators/Elliptic Curve Calculator/image/readme/1726495436282.png new file mode 100644 index 000000000..8961abdef Binary files /dev/null and b/Calculators/Elliptic Curve Calculator/image/readme/1726495436282.png differ diff --git a/Calculators/Elliptic Curve Calculator/index.html b/Calculators/Elliptic Curve Calculator/index.html new file mode 100644 index 000000000..fc9264c5a --- /dev/null +++ b/Calculators/Elliptic Curve Calculator/index.html @@ -0,0 +1,151 @@ + + + + + + Elliptic Curve Calculator + + + + +
+

Elliptic Curve Calculator

+ + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+
+
+
+
+ + Note: Ensure that the values entered for points lie on the elliptic + curve defined by the parameters a, b, and p, and that the curve is + valid (i.e., 4a3 + 27b2 ≠ 0 mod p). + +
+ + +
+
+ Point Addition: +
+
+ Point Negation: +
+
+ Scalar Multiplication: +
+
+ All Points on the Curve: +
+
+
+
+ + + + diff --git a/Calculators/Elliptic Curve Calculator/script.js b/Calculators/Elliptic Curve Calculator/script.js new file mode 100644 index 000000000..1ded4e21e --- /dev/null +++ b/Calculators/Elliptic Curve Calculator/script.js @@ -0,0 +1,151 @@ +const INF = null; + +document.addEventListener("DOMContentLoaded", () => { + setMode("addition"); +}); + +function setMode(mode) { + // Hide all input sections initially + document.getElementById("point1").style.display = "none"; + document.getElementById("point2").style.display = "none"; + document.getElementById("scalar").style.display = "none"; + + // Hide all result sections + document.getElementById("additionResult").style.display = "none"; + document.getElementById("negationResult").style.display = "none"; + document.getElementById("multiplicationResult").style.display = "none"; + document.getElementById("allPointsResult").style.display = "none"; + + // Show relevant inputs based on the mode + if (mode === "addition") { + document.getElementById("point1").style.display = "flex"; + document.getElementById("point2").style.display = "flex"; + document.getElementById("additionResult").style.display = "block"; + } else if (mode === "negation") { + document.getElementById("point1").style.display = "flex"; + document.getElementById("negationResult").style.display = "block"; + } else if (mode === "multiplication") { + document.getElementById("point1").style.display = "flex"; + document.getElementById("scalar").style.display = "flex"; + document.getElementById("multiplicationResult").style.display = "block"; + } else if (mode === "allPoints") { + document.getElementById("allPointsResult").style.display = "block"; + } +} + +function modInverse(a, p) { + for (let i = 1; i < p; i++) { + if ((a * i) % p === 1) { + return i; + } + } + return null; +} + +function pointAddition(p1, p2, a, p) { + if (p1 === INF) return p2; + if (p2 === INF) return p1; + + let [x1, y1] = p1; + let [x2, y2] = p2; + + let s; + if (x1 === x2 && y1 === y2) { + s = ((3 * x1 * x1 + a) * modInverse(2 * y1, p)) % p; + } else { + s = ((y2 - y1) * modInverse(x2 - x1, p)) % p; + } + + const x3 = (s * s - x1 - x2) % p; + const y3 = (s * (x1 - x3) - y1) % p; + + return [(x3 + p) % p, (y3 + p) % p]; +} + +function pointNegation(point, modulus) { + const [x, y] = point; + return [x, (modulus - y) % modulus]; +} + +function scalarMultiplication(k, point, a, p) { + let result = INF; + while (k > 0) { + if (k % 2 === 1) { + result = pointAddition(result, point, a, p); + } + k = Math.floor(k / 2); + point = pointAddition(point, point, a, p); + } + return result; +} + +// Function to generate all points on the elliptic curve +function generateAllPoints(a, b, p) { + const points = []; + for (let x = 0; x < p; x++) { + for (let y = 0; y < p; y++) { + if ((y * y) % p === (x * x * x + a * x + b) % p) { + points.push([x, y]); + } + } + } + return points; +} + +function calculate() { + const a = parseInt(document.getElementById("a").value); + const b = parseInt(document.getElementById("b").value); + const p = parseInt(document.getElementById("p").value); + const x1 = parseInt(document.getElementById("x1").value); + const y1 = parseInt(document.getElementById("y1").value); + const x2 = parseInt(document.getElementById("x2").value); + const y2 = parseInt(document.getElementById("y2").value); + const k = parseInt(document.getElementById("k").value); + + const point = [x1, y1]; + const point2 = [x2, y2]; + + const additionResult = pointAddition(point, point2, a, p); + const negationResult = pointNegation(point, p); + const multiplicationResult = scalarMultiplication(k, point, a, p); + + document.getElementById( + "additionResult" + ).textContent = `Point Addition: (${additionResult[0]}, ${additionResult[1]})`; + + document.getElementById( + "negationResult" + ).textContent = `Point Negation: (${negationResult[0]}, ${negationResult[1]})`; + document.getElementById( + "multiplicationResult" + ).textContent = `Scalar Multiplication: (${multiplicationResult[0]}, ${multiplicationResult[1]})`; + + // Generate and display all points on the curve + const allPoints = generateAllPoints(a, b, p); + const pointsText = allPoints + .map((point) => `(${point[0]}, ${point[1]})`) + .join(", "); + document.getElementById( + "allPointsResult" + ).textContent = `All Points on the Curve: ${pointsText}`; + const mode = document + .querySelector(".btn.btn-primary") + .textContent.toLowerCase(); + if (mode.includes("addition")) { + document.getElementById( + "additionResult" + ).innerHTML = `Point Addition: (${x1}, ${y1}) + (${x2}, ${y2}) = [Result Here]`; + } else if (mode.includes("negation")) { + document.getElementById( + "negationResult" + ).innerHTML = `Point Negation: -(${x1}, ${y1}) = [Result Here]`; + } else if (mode.includes("multiplication")) { + document.getElementById( + "multiplicationResult" + ).innerHTML = `Scalar Multiplication: ${k} * (${x1}, ${y1}) = [Result Here]`; + } else if (mode.includes("all points")) { + document.getElementById( + "allPointsResult" + ).innerHTML = `All Points on the Curve: [List of Points]`; + } +} diff --git a/Calculators/Elliptic Curve Calculator/style.css b/Calculators/Elliptic Curve Calculator/style.css new file mode 100644 index 000000000..0c6f31638 --- /dev/null +++ b/Calculators/Elliptic Curve Calculator/style.css @@ -0,0 +1,65 @@ +body { + background: rgb(238, 174, 202); + background: radial-gradient( + circle, + rgba(238, 174, 202, 1) 0%, + rgba(148, 187, 233, 1) 100% + ); +} + +/* Title Styling */ +.title { + font-size: 3rem; + font-family: "Montserrat", sans-serif; + color: #0077ff; + text-transform: uppercase; + letter-spacing: 2px; + font-weight: 700; + text-align: center; + animation: colorChange 4s linear infinite; +} + +@keyframes colorChange { + 0% { + color: #0077ff; + } + 25% { + color: #ff0077; + } + 50% { + color: #00ff77; + } + 75% { + color: #ff7700; + } + 100% { + color: #0077ff; + } +} + +.results .alert { + font-size: 1.2rem; +} + +button { + width: 100%; + font-size: 1.1rem; +} + +.mod { + background-color: #6c757d; /* Original button background */ + color: white; /* Text color */ + padding: 10px 20px; + font-size: 16px; + border: none; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s ease, transform 0.2s ease; +} + +.mod:hover { + background-color: #5a6268; /* Darken background on hover */ + color: #fff; /* Keep text white */ + transform: scale(1.05); /* Slight zoom on hover */ + box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); /* Add a subtle shadow */ +} diff --git a/index.html b/index.html index ae6fdb43f..d58549062 100644 --- a/index.html +++ b/index.html @@ -1994,6 +1994,20 @@

Calculates Area and Perimeter for Ellipse and Hyperbola.

+
+
+

Ellipse Curve Calculator

+

Calculates points on curve, addition, negation and scalar multiplication of points.

+ +
+

Emirp Number Calculator