import Input from "./Input"; import { Variable } from "./Complete"; import { createSignal } from "solid-js"; function Simple() { // Usually 2000 or 4000 bits long const [n, setN] = createSignal(23n); const [g, setG] = createSignal(5n); const [alicePrivateKey, setAlicePrivateKey] = createSignal(null); const alicePublicKey = () => alicePrivateKey() ? g() ** alicePrivateKey() % n() : null; const [bobPublicKey, setBobPublicKey] = createSignal(null); function handlePrivateKeyInput(setPrivateKey) { return (event) => { if (event.target.value > n()) { console.debug("Private key has to be smaller than n"); return; } if (event.target.value < 1n) { console.debug("Private key has to be bigger than 0"); return; } setPrivateKey(BigInt(event.target.value)); }; } const sharedSecret = () => { if (!bobPublicKey() || !alicePrivateKey()) { return null; } return bobPublicKey() ** alicePrivateKey() % n(); }; let alicePrivateKeyInput; let bobPublicKeyInput; return (

Denke dir eine Zahl zwischen 1 und 23

Aber sag sie niemanden!

Das Ergebnis Claas mitteilen:
A ={" "} g a mod{" "} n

{/* "A" just for spacing */} A ={" "} {g().toString()} {alicePrivateKey()?.toString() || "a"} {" "} mod {n().toString()}

{/* "A" just for spacing */} A ={" "} {alicePublicKey()?.toString() ?? "?"} {" "} {!alicePublicKey() && ( {" "} (Bitte eine Zahl a {" "} eingeben) )}

Zahl von Claas:

{ setBobPublicKey(BigInt(event.target.value)); }} ref={bobPublicKeyInput} />

Unser Geheimnis
s ={" "} B a mod{" "} n

{/* "A" just for spacing */} B ={" "} {bobPublicKey()?.toString() || "B"} {alicePrivateKey()?.toString() || "a"} {" "} mod {n().toString()}

{/* "A" just for spacing */} B ={" "} {function () { if (!alicePrivateKey()) return ( {" "} (Bitte gib eine Zahl{" "} a ein) ); if (!bobPublicKey()) return ( {" "} (Bitte Claas' Zahl{" "} B{" "} eingeben) ); return ( {sharedSecret()?.toString()} ); }}

); } export default Simple;