<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ECC Decode Tool — Auto URL</title>
<style>
body {
font-family: "Segoe UI", Arial, sans-serif;
background: linear-gradient(135deg, #1e1e2f, #2d2d44);
color: #eee;
padding: 40px;
}
h1 {
text-align: center;
margin-bottom: 30px;
font-weight: 300;
color: #fff;
}
.container {
max-width: 700px;
margin: auto;
background: #2b2b3d;
padding: 25px;
border-radius: 12px;
box-shadow: 0 0 20px rgba(0,0,0,0.4);
}
label {
font-size: 15px;
margin-top: 10px;
display: block;
color: #ccc;
}
input {
width: 100%;
padding: 10px;
margin-top: 6px;
border-radius: 6px;
border: none;
background: #3a3a4f;
color: #fff;
font-size: 15px;
}
button {
width: 100%;
padding: 12px;
margin-top: 20px;
background: #4a8cff;
border: none;
border-radius: 6px;
color: white;
font-size: 16px;
cursor: pointer;
transition: 0.2s;
}
button:hover {
background: #2f6dff;
}
pre {
background: #111;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
color: #0f0;
overflow-x: auto;
}
</style>
</head>
<body>
<h1>ECC Decode Tool — Auto‑Open URL</h1>
<div class="container">
<label>C.x</label>
<input id="cx" type="text" placeholder="Enter C.x">
<label>C.y</label>
<input id="cy" type="text" placeholder="Enter C.y">
<label>Scalar k</label>
<input id="k" type="number" placeholder="Enter scalar k">
<button onclick="decodeAndTrigger()">Decode & Auto‑Open URL</button>
<pre id="output"></pre>
</div>
<script>
// secp256k1 parameters
const p = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");
const n = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
// Point class
class Point {
constructor(x, y) { this.x = x; this.y = y; }
}
// Modular exponentiation
function modPow(base, exp, mod) {
let r = 1n;
base %= mod;
while (exp > 0) {
if (exp & 1n) r = (r * base) % mod;
base = (base * base) % mod;
exp >>= 1n;
}
return r;
}
// Modular inverse
function modInv(a, m) {
return modPow(a, m - 2n, m);
}
// Point addition
function pointAdd(P, Q) {
if (P === null) return Q;
if (Q === null) return P;
if (P.x === Q.x && P.y !== Q.y) return null;
let m;
if (P.x === Q.x && P.y === Q.y) {
m = (3n * P.x * P.x) * modInv(2n * P.y, p) % p;
} else {
m = (Q.y - P.y) * modInv(Q.x - P.x, p) % p;
}
const rx = (m*m - P.x - Q.x) % p;
const ry = (m*(P.x - rx) - P.y) % p;
return new Point((rx+p)%p, (ry+p)%p);
}
// Scalar multiplication
function scalarMult(k, P) {
let R = null;
let A = P;
while (k > 0n) {
if (k & 1n) R = pointAdd(R, A);
A = pointAdd(A, A);
k >>= 1n;
}
return R;
}
// Convert integer → text
function intToText(x) {
let hex = x.toString(16);
if (hex.length % 2) hex = "0" + hex;
let bytes = new Uint8Array(hex.match(/.{1,2}/g).map(b => parseInt(b,16)));
return new TextDecoder().decode(bytes);
}
// Decode + auto-detect URL
function decodeAndTrigger() {
const cx = BigInt(document.getElementById("cx").value);
const cy = BigInt(document.getElementById("cy").value);
const k = BigInt(document.getElementById("k").value);
const C = new Point(cx, cy);
const k_inv = modInv(k, n);
const P = scalarMult(k_inv, C);
let recovered = "";
try {
recovered = intToText(P.x);
} catch {
recovered = "(invalid UTF‑8 data)";
}
const output = document.getElementById("output");
output.textContent =
"k⁻¹ mod n:\n" + k_inv + "\n\n" +
"Decoded point P:\n" + JSON.stringify(P, null, 2) + "\n\n" +
"Recovered text:\n" + recovered;
// Auto-detect URL
const urlPattern = /^(https?:\/\/|www\.)[^\s]+$/i;
if (urlPattern.test(recovered)) {
output.textContent += "\n\nDetected URL → Opening…";
setTimeout(() => window.location.href = recovered, 800);
} else {
output.textContent += "\n\nNot a URL → Displayed as text.";
}
}
</script>
</body>
</html>

