Friday, June 12, 2026

HTML script code for the elliptic curve decryption

 




<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>ECC Decode Tool (k⁻¹ · C)</title>

<style>

    body {

        font-family: Arial, sans-serif;

        background: #f0f0f0;

        padding: 20px;

    }

    .box {

        background: white;

        padding: 15px;

        border-radius: 8px;

        margin-bottom: 20px;

        box-shadow: 0 0 5px rgba(0,0,0,0.1);

    }

    input {

        width: 100%;

        padding: 8px;

        margin-top: 5px;

        margin-bottom: 10px;

        border-radius: 5px;

        border: 1px solid #aaa;

    }

    button {

        padding: 10px 20px;

        background: #0078ff;

        color: white;

        border: none;

        border-radius: 5px;

        cursor: pointer;

    }

    button:hover { background: #005fcc; }

    pre {

        background: #222;

        color: #0f0;

        padding: 10px;

        border-radius: 5px;

        overflow-x: auto;

    }

</style>

</head>

<body>


<h2>ECC Decode Tool — Compute P = k⁻¹ · C</h2>


<div class="box">

    <label>C.x:</label>

    <input id="cx" type="text">


    <label>C.y


    <label>Scalar k:</label>

    <input id="k" type="number">


    <button onclick="decodeECC()">Decode</button>

</div>


<div class="box">

    <h3>Decoded Output</h3>

    <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 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);

}


// Main decode function

function decodeECC() {

    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)"; }


    document.getElementById("output").textContent =

        "k⁻¹ mod n:\n" + k_inv + "\n\n" +

        "Decoded point P:\n" + JSON.stringify(P, null, 2) + "\n\n" +

        "Recovered message:\n" + recovered;

}

</script>


</body>

</html>

No comments:

HTML script code for the elliptic curve decryption

  <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>ECC Decode Tool (k⁻¹ · C)</title...