Z25422

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z25422"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z25393",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z25393(Z25393K1, Z25393K2) {\n\tif (Z25393K1.length !== 64 || Z25393K2.length !== 64) {\n\t\tthrow new Error(\"Invalid length\");\n\t}\n\t\n    function hex2int(hex) {\n        const bytes = [];\n        for (let i = 0; i \u003C hex.length; i += 2) {\n            bytes.push(parseInt(hex.slice(i, i + 2), 16));\n        }\n        let result = 0n;\n        for (let i = 0; i \u003C bytes.length; i++) {\n            result |= BigInt(bytes[i]) \u003C\u003C (8n * BigInt(i));\n        }\n        return result;\n    }\n\n    function int2hex(n) {\n        const bytes = [];\n        for (let i = 0; i \u003C 32; i++) {\n            bytes.push(Number((n \u003E\u003E BigInt(8 * i)) \u0026 0xffn));\n        }\n        return bytes.map(b =\u003E b.toString(16).padStart(2, '0')).join('');\n    }\n\n    const P = (1n \u003C\u003C 255n) - 19n;\n\n    function pointAdd([xn, zn], [xm, zm], [x_diff, z_diff]) {\n        return [((z_diff \u003C\u003C 2n) * ((xm * xn - zm * zn) ** 2n)) % P, ((x_diff \u003C\u003C 2n) * ((xm * zn - zm * xn) ** 2n)) % P];\n    }\n\n    function pointDouble([xn, zn]) {\n        const xn2 = xn ** 2n;\n        const zn2 = zn ** 2n;\n        const xzn = xn * zn;\n        \n        return [(xn2 - zn2) ** 2n % P, (4n * xzn * (xn2 + 486662n * xzn + zn2)) % P];\n    }\n\n    function modPow(base, exp, mod) {\n        let result = 1n;\n        base %= mod;\n        while (exp \u003E 0n) {\n            if (exp \u0026 1n) result = (result * base) % mod;\n            base = (base * base) % mod;\n            exp \u003E\u003E= 1n;\n        }\n        return result;\n    }\n\n    function curve25519(base, n) {\n        const zero = [1n, 0n];\n        const one = [base, 1n];\n        let mP = [...zero];\n        let m1P = [...one];\n\n        for (let i = 255; i \u003E= 0; i--) {\n            const bit = (n \u003E\u003E BigInt(i)) \u0026 1n;\n\n            if (bit === 1n) {\n                const tmp = mP;\n                mP = m1P;\n                m1P = tmp;\n            }\n\n            const new_mP = pointDouble(mP);\n            const new_m1P = pointAdd(mP, m1P, one);\n\n            if (bit === 1n) {\n                mP = new_m1P;\n                m1P = new_mP;\n            } else {\n                mP = new_mP;\n                m1P = new_m1P;\n            }\n        }\n\n        const [x, z] = mP;\n        const invZ = modPow(z, P - 2n, P);\n        return (x * invZ) % P;\n    }\n\n    const base = hex2int(Z25393K1);\n    let secret = hex2int(Z25393K2);\n    secret \u0026= ~7n;\n    secret \u0026= ~(128n \u003C\u003C (8n * 31n));\n    secret |= (64n \u003C\u003C (8n * 31n));\n\n    const result = curve25519(base, secret);\n    return int2hex(result);\n}\n"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "X25519 in javascript"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}