Files
cryptoseals/backend/src/main/resources/get/cesare.js
elisabetta 48f0c35039
All checks were successful
Deploy / trigger (push) Successful in 24s
hm
2026-04-20 22:22:49 +02:00

36 lines
1.4 KiB
JavaScript

async function encrypt() {
const plaintext = document.getElementById("plaintext").value;
const key = document.getElementById("key").value;
if (!plaintext) return alert("Inserisci del testo!");
try {
const risposta = await fetch("/seal/caesar/encrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
// Invia il testo e la chiave (convertita in numero) al server
body: JSON.stringify({ plaintext: plaintext, key: parseInt(key) })
});
document.getElementById("ciphertext").value = await risposta.text();
} catch (e) { alert("Errore di connessione con le API di caesar!"); }
}
async function decrypt() {
const c = document.getElementById("ciphertext").value;
if (!c) return alert("Nessun testo da decifrare!");
try {
const res = await fetch("/seal/caesar/decrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ciphertext: c })
});
const data = await res.json();
document.getElementById("decodedtext").value = JSON.stringify(data, null, 2);
} catch (e) { alert("Errore di connessione!"); }
}
// Gestione Menu Mobile
function toggleMenu() {
document.getElementById("nav-links").classList.toggle("active");
}
// Anno dinamico Footer
document.getElementById("year").innerText = new Date().getFullYear();