let lastDecodedPoint = null; // store P for later use
function convertIntToText() {
const terminal = document.getElementById("terminal");
if (!lastDecodedPoint) {
terminal.textContent += "\nNo decoded point available. Run decoder first.\n";
return;
}
terminal.textContent += "\nConverting P.x to text...\n";
let text = "(invalid UTF‑8)";
try {
text = intToText(lastDecodedPoint.x);
} catch {}
terminal.textContent += "Decoded text:\n" + text + "\n";
const urlPattern = /^(https?:\/\/|www\.)[^\s]+$/i;
if (urlPattern.test(text)) {
terminal.textContent += "This looks like a URL (but not opening it).\n";
} else {
terminal.textContent += "This is plain text.\n";
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ECC Encoded URL Redirect</title>
<style>
body {
background: #0d0d0d;
color: #00ff99;
font-family: Consolas, monospace;
padding: 40px;
}
h1 {
text-align: center;
color: #00ffaa;
font-weight: 300;
margin-bottom: 30px;
}
.box {
max-width: 700px;
margin: auto;
background: #000;
border: 2px solid #00ff99;
padding: 25px;
border-radius: 10px;
}
label {
display: block;
margin-top: 15px;
color: #00ffaa;
}
input {
width: 100%;
padding: 10px;
background: #111;
border: 1px solid #00ff99;
color: #00ff99;
border-radius: 5px;
font-family: Consolas;
}
button {
margin-top: 20px;
width: 100%;
padding: 12px;
background: #00ff99;
color: #000;
font-weight: bold;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background: #00ffaa;
}
pre {
background: #000;
border: 1px solid #00ff99;
padding: 15px;
margin-top: 20px;
color: #00ff99;
overflow-x: auto;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>ECC Encoded URL Redirect</h1>
<div class="box">
<label>C.x</label>
<input id="cx" placeholder="Paste C.x">
<label>C.y</label>
<input id="cy" placeholder="Paste C.y">
<label>Scalar k</label>
<input id="k" placeholder="Enter scalar k">
<button onclick="decodeAndRedirect()">Decode & Redirect</button>
<pre id="log">Waiting for ECC input…</pre>
</div>
<script>
// secp256k1 parameters
const p = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");
const n = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
class Point {
constructor(x, y) { this.x = x; this.y = y; }
}
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;
}
function modInv(a, m) {
return modPow(a, m - 2n, m);
}
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);
}
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;
}
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);
}
function decodeAndRedirect() {
const log = document.getElementById("log");
log.textContent = "Decoding ECC data…\n";
const cx = BigInt(document.getElementById("cx").value);
const cy = BigInt(document.getElementById("cy").value);
const k = BigInt(document.getElementById("k").value);
log.textContent += "Computing k⁻¹ mod n…\n";
const k_inv = modInv(k, n);
log.textContent += "Performing P = k⁻¹ · C…\n";
const C = new Point(cx, cy);
const P = scalarMult(k_inv, C);
log.textContent += "Recovered point P:\n" + JSON.stringify(P, null, 2) + "\n\n";
log.textContent += "Converting P.x to text…\n";
let text = "(invalid UTF‑8)";
try { text = intToText(P.x); } catch {}
log.textContent += "Decoded text:\n" + text + "\n\n";
const urlPattern = /^(https?:\/\/|www\.)[^\s]+$/i;
if (urlPattern.test(text)) {
log.textContent += "Detected URL → Redirecting…\n";
setTimeout(() => window.location.href = text, 1200);
} else {
log.textContent += "Not a URL. Displaying text only.\n";
}
}
</script>
</body>
</html>
<input id="cx" value="1234567890...">
<input id="cy" value="9876543210...">
<input id="k" value="12345">
const Cx = "123456789...";
const Cy = "987654321...";
const k = "12345";


















No comments:
Post a Comment