Fixed structure

This commit is contained in:
2026-03-27 21:48:04 +01:00
parent b99ea98460
commit c382d1c514
13 changed files with 1027 additions and 811 deletions

View File

@@ -1,47 +0,0 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>CryptoSeals - Home</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navbar">
<a href="index.html" class="nav-brand">
<img src="seal1.png" height="80" alt="🦭" onerror="this.style.display='none'; this.nextElementSibling.style.display='inline';">
<span style="display:none;"><img src="seal1.png"></span> CryptoSeals
</a>
<ul class="nav-links">
<li><a href="rsa.html">Algoritmo RSA</a></li>
<li><a href="cesare.html">Cesare</a></li>
<li><a href="vigenere.html">Vigenère</a></li>
<li><a href="team.html">Il Team</a></li>
</ul>
</nav>
<div></div>
<div class="container">
<h1>Welcome to CryptoSeals</h1>
<p class="descrizione">
Dive deep, Seal your data.<br>
<br><br>
<i>Click any tool in the bar on the right to start!</i>
</p>
<img src="/target/classes/seal1.png" alt="Mascotte CryptoSeals" style="max-width: 300px; border-radius: 20px; box-shadow: 0 10px 20px rgba(0,0,0,0.1);" onerror="this.style.display='none';">
</div>
<footer>
<div class="copyright">
<span>
<a href="/privacy-policy/">Privacy Policy</a> &nbsp;
</span>
<span>
© <span class="" data-timestamp="2026-03-26T11:39:53Z" data-function="format" data-format="YYYY" data-refresh="0">2026</span> CryptoSeals
</span>
</div>
</footer>
</body>
</html>

View File

@@ -1,168 +0,0 @@
/* Importiamo Inter per la massima leggibilità */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
/* --- STILI BASE (DARK) --- */
body, h1, h2, p, ul, li { margin: 0; padding: 0; }
body {
font-family: 'Inter', system-ui, -apple-system, sans-serif;
background-color: #0c1221; /* Fondo quasi nero, molto profondo */
color: #f1f5f9; /* Testo chiaro ghiaccio */
padding-top: 100px;
-webkit-font-smoothing: antialiased; /* Rende il font più nitido su Mac */
}
footer {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
font-size: 0.85em;
position: absolute;
padding-top: 1rem;
z-index: 1050;
width: 100%;
margin-top: 3rem;
background: var(--color-bg-footer);
box-shadow: inset 0 2px 5px 0 rgba(0, 0, 0, 0.16),
inset 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
footer {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
font-size: 0.85em;
position: absolute;
padding-top: 1rem;
z-index: 1050;
width: 100%;
margin-top: 3rem;
background: var(--color-bg-footer);
box-shadow: inset 0 2px 5px 0 rgba(0, 0, 0, 0.16),
inset 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
footer .copyright {
display: flex;
flex-direction: row;
justify-content: space-between;
width: 100%;
margin-top: 2rem;
padding: 1.5rem 2em;
text-align: right;
border-top: 1px solid #ffffff10;
}
/* --- NAVBAR (EFFETTO VETRO SCURO) --- */
.navbar {
background-color: rgba(17, 24, 39, 0.8);
backdrop-filter: blur(12px); /* Effetto vetro sfocato */
position: fixed;
top: 0;
width: 100%;
height: 75px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 40px;
box-sizing: border-box;
z-index: 1000;
border-bottom: 1px solid #1e293b;
}
.nav-brand { display: flex; align-items: center; gap: 12px; font-size: 24px; font-weight: 800; color: #f1f5f9; text-decoration: none; letter-spacing: -0.5px;}
.nav-brand span { font-size: 28px; color: #0688d4; /* Accento Ciano Ghiaccio */ }
.nav-links { list-style: none; display: flex; gap: 30px; }
.nav-links a { color: #94a3b8; text-decoration: none; font-weight: 500; font-size: 15px; transition: 0.2s;}
.nav-links a:hover, .nav-links a.active { color: #06b6d4; font-weight: 600; }
/* --- CONTENITORE CENTRALE --- */
.container { max-width: 1100px; margin: 0 auto 60px auto; padding: 20px; text-align: center; }
h1 { font-size: 48px; color: #f1f5f9; margin-bottom: 15px; font-weight: 900; letter-spacing: -1.5px; }
p.descrizione { font-size: 18px; color: #94a3b8; line-height: 1.6; margin-bottom: 50px; max-width: 700px; margin-left: auto; margin-right: auto;}
/* --- SCATOLA PRINCIPALE (MODERN DARK) --- */
.crypto-box {
background-color: #111827; /* Slate dark */
margin: 0 auto;
padding: 50px;
border-radius: 28px;
border: 1px solid #1e293b;
box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
text-align: left;
}
label { font-weight: 600; color: #94a3b8; font-size: 14px; margin-bottom: 10px; display: block; text-transform: uppercase; letter-spacing: 1px; }
/* Input, Select, Textarea (Modern Dark) */
textarea, select {
width: 100%;
padding: 18px;
border-radius: 14px;
border: 1px solid #1e293b;
background-color: #1f2937; /* Input leggermente più chiaro */
color: #f1f5f9;
font-family: 'Inter', system-ui, -apple-system, sans-serif;
font-size: 16px;
box-sizing: border-box;
transition: all 0.3s ease;
margin-bottom: 25px;
line-height: 1.6;
}
textarea:focus, select:focus { outline: none; border-color: #06b6d4; background-color: #111827; box-shadow: 0 0 0 4px rgba(6, 182, 212, 0.15); }
textarea { height: 180px; resize: none; }
textarea::placeholder { color: #4b5563; }
/* --- DEFINIZIONE ANIMAZIONE PULSANTE --- */
@keyframes glitchPulse {
0% { border-color: #1e293b; box-shadow: 0 0 0 0 rgba(6, 182, 212, 0); }
50% { border-color: #06b6d4; box-shadow: 0 0 15px 2px rgba(6, 182, 212, 0.3); }
100% { border-color: #1e293b; box-shadow: 0 0 0 0 rgba(6, 182, 212, 0); }
}
/* Applichiamo l'animazione alla casella di input principale */
.pulse-textarea {
animation: glitchPulse 2.5s infinite ease-in-out; /* Pulsazione lenta e continua */
}
.pulse-textarea:focus {
animation: none; /* Smette di pulsare quando ci scrivi dentro */
}
/* --- LAYOUT A COLONNE --- */
.crypto-columns {
display: flex;
gap: 35px;
}
.crypto-col {
flex: 1;
display: flex;
flex-direction: column;
}
/* --- BOTTONI--- */
button {
background: linear-gradient(135deg, #0891b2, #06b6d4); /* Ciano Gradient */
color: #0b0f19;
border: none;
padding: 18px 25px;
font-size: 16px;
border-radius: 14px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 700;
width: 100%;
text-transform: uppercase;
letter-spacing: 1px;
}
button:hover { transform: translateY(-3px); box-shadow: 0 12px 25px rgba(6, 182, 212, 0.3); }
button:active { transform: translateY(-1px); }
/* Bottone Decifra (Verde Neon) */
.btn-green { background: linear-gradient(135deg, #059669, #10b981); color: #0b0f19;}
.btn-green:hover { box-shadow: 0 12px 25px rgba(16, 185, 129, 0.3); }
/* Responsive */
@media (max-width: 800px) {
.crypto-columns { flex-direction: column; gap: 0; }
}

View File

@@ -1,18 +1,18 @@
package com.crypto;
import java.util.Scanner;
public class Caesar {
public static void encode(Scanner sc){
String alphabet = "abcdefghijklmnopqrstuvwxyz";
System.out.println("Digita il testo in chiaro da cifrare:");
String base = sc.nextLine();
System.out.println("Digita il valore della chiave:");
int key = sc.nextInt();
char encoded[] = base.toCharArray();
for(int i = 0; i < base.length(); i++){
encoded[i] = alphabet.charAt(alphabet.indexOf(encoded[i]) + key % 26);
}
System.out.println(encoded);
}
}
package com.crypto;
import java.util.Scanner;
public class Caesar {
public static void encode(Scanner sc){
String alphabet = "abcdefghijklmnopqrstuvwxyz";
System.out.println("Digita il testo in chiaro da cifrare:");
String base = sc.nextLine();
System.out.println("Digita il valore della chiave:");
int key = sc.nextInt();
char encoded[] = base.toCharArray();
for(int i = 0; i < base.length(); i++){
encoded[i] = alphabet.charAt(alphabet.indexOf(encoded[i]) + key % 26);
}
System.out.println(encoded);
}
}

View File

@@ -1,140 +1,140 @@
package com.crypto;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
//
// Menu
//
private static int scegliDimensioneChiave(Scanner scanner) {
int bits = 0;
while (bits == 0) {
System.out.println("\nSeleziona la dimensione della chiave:");
System.out.println(" [1] 512 bit (Solo uso didattico)");
System.out.println(" [2] 1024 bit (Deprecata, solo test)");
System.out.println(" [3] 2048 bit (Standard attuale)");
System.out.println(" [4] 3072 bit (Ottimo compromesso)");
System.out.println(" [5] 4096 bit (Alta sicurezza)");
System.out.print("Scelta (1-5): ");
try {
int scelta = Integer.parseInt(scanner.nextLine().trim());
// Assegniamo i bit in base alla scelta
switch (scelta) {
case 1 -> bits = 512;
case 2 -> bits = 1024;
case 3 -> bits = 2048;
case 4 -> bits = 3072;
case 5 -> bits = 4096;
default -> System.out.println("❌ Scelta non valida. Inserisci un numero da 1 a 5.");
}
} catch (NumberFormatException e) {
System.out.println("❌ Errore: Inserisci un numero valido.");
}
}
System.out.println("Selezionata chiave da " + bits + " bit.");
return bits;
}
// Main
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("==========================================");
System.out.println(" RSA CRYPTO ENGINE ");
System.out.println("==========================================");
// --- 1. SETUP DELLE CHIAVI ---
int dimChiave = scegliDimensioneChiave(scanner);
System.out.println("\n⏳ Generazione delle chiavi in corso...");
// Passiamo dimChiave / 2 come facevi prima per p e q
RSA.RSAkeys chiavi = RSA.defkeys(dimChiave / 2);
System.out.println("> Chiavi generate con successo!");
boolean continua = true;
// --- CICLO PRINCIPALE ---
while (continua) {
System.out.println("\n------------------------------------------");
System.out.println("Cosa vuoi fare?");
System.out.println(" [1] Cifra un numero");
System.out.println(" [2] Cifra una stringa");
System.out.println(" [3] Rigenera le chiavi");
System.out.println(" [0] Esci");
System.out.println("------------------------------------------");
System.out.print("Scelta: ");
int scelta = -1;
try {
scelta = Integer.parseInt(scanner.nextLine().trim());
} catch (NumberFormatException ignored) {
}
System.out.println();
switch (scelta) {
case 1 -> {
// MODALITÀ NUMERO
System.out.print("Inserisci il numero da cifrare: ");
try {
BigInteger m = new BigInteger(scanner.nextLine().trim());
System.out.println("> Cifratura in corso...");
BigInteger c = RSA.encrypt(m, chiavi.e(), chiavi.n());
System.out.println("Cifrato:\n" + c);
System.out.println("\n> Decifratura in corso...");
BigInteger dec = RSA.decrypt(c, chiavi.d(), chiavi.n());
System.out.println("Decifrato:\n" + dec);
} catch (IllegalArgumentException ex) {
System.out.println("> Errore: Assicurati di inserire un numero valido.");
}
}
case 2 -> {
// MODALITÀ STRINGA
System.out.print("Inserisci il testo da cifrare: ");
String input = scanner.nextLine();
System.out.println("> Cifratura in corso...");
String cifrato = RSA.encrypt(input, chiavi.e(), chiavi.n());
if (cifrato != null && !cifrato.isEmpty()) {
// 2. SOLO PER LA STAMPA: nascondiamo il binario convertendolo in Base64
String base64 = java.util.Base64.getEncoder().encodeToString(cifrato.getBytes());
System.out.println("Cifrato (Base64):\n" + base64);
}
System.out.println("\n> Decifratura in corso...");
String dec = RSA.decrypt(cifrato, chiavi.d(), chiavi.n());
System.out.println("Decifrato:\n" + dec);
}
case 3 -> {
// RIGENERA CHIAVI
dimChiave = scegliDimensioneChiave(scanner);
System.out.println("\n> Generazione delle chiavi in corso...");
chiavi = RSA.defkeys(dimChiave / 2);
System.out.println("> Chiavi rigenerate con successo!");
}
case 0 -> {
continua = false;
System.out.println("Chiusura del motore RSA. Alla prossima!");
}
default -> System.out.println("> Scelta non valida, riprova.");
}
}
scanner.close();
}
}
package com.crypto;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
//
// Menu
//
private static int scegliDimensioneChiave(Scanner scanner) {
int bits = 0;
while (bits == 0) {
System.out.println("\nSeleziona la dimensione della chiave:");
System.out.println(" [1] 512 bit (Solo uso didattico)");
System.out.println(" [2] 1024 bit (Deprecata, solo test)");
System.out.println(" [3] 2048 bit (Standard attuale)");
System.out.println(" [4] 3072 bit (Ottimo compromesso)");
System.out.println(" [5] 4096 bit (Alta sicurezza)");
System.out.print("Scelta (1-5): ");
try {
int scelta = Integer.parseInt(scanner.nextLine().trim());
// Assegniamo i bit in base alla scelta
switch (scelta) {
case 1 -> bits = 512;
case 2 -> bits = 1024;
case 3 -> bits = 2048;
case 4 -> bits = 3072;
case 5 -> bits = 4096;
default -> System.out.println("❌ Scelta non valida. Inserisci un numero da 1 a 5.");
}
} catch (NumberFormatException e) {
System.out.println("❌ Errore: Inserisci un numero valido.");
}
}
System.out.println("Selezionata chiave da " + bits + " bit.");
return bits;
}
// Main
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("==========================================");
System.out.println(" RSA CRYPTO ENGINE ");
System.out.println("==========================================");
// --- 1. SETUP DELLE CHIAVI ---
int dimChiave = scegliDimensioneChiave(scanner);
System.out.println("\n⏳ Generazione delle chiavi in corso...");
// Passiamo dimChiave / 2 come facevi prima per p e q
RSA.RSAkeys chiavi = RSA.defkeys(dimChiave / 2);
System.out.println("> Chiavi generate con successo!");
boolean continua = true;
// --- CICLO PRINCIPALE ---
while (continua) {
System.out.println("\n------------------------------------------");
System.out.println("Cosa vuoi fare?");
System.out.println(" [1] Cifra un numero");
System.out.println(" [2] Cifra una stringa");
System.out.println(" [3] Rigenera le chiavi");
System.out.println(" [0] Esci");
System.out.println("------------------------------------------");
System.out.print("Scelta: ");
int scelta = -1;
try {
scelta = Integer.parseInt(scanner.nextLine().trim());
} catch (NumberFormatException ignored) {
}
System.out.println();
switch (scelta) {
case 1 -> {
// MODALITÀ NUMERO
System.out.print("Inserisci il numero da cifrare: ");
try {
BigInteger m = new BigInteger(scanner.nextLine().trim());
System.out.println("> Cifratura in corso...");
BigInteger c = RSA.encrypt(m, chiavi.e(), chiavi.n());
System.out.println("Cifrato:\n" + c);
System.out.println("\n> Decifratura in corso...");
BigInteger dec = RSA.decrypt(c, chiavi.d(), chiavi.n());
System.out.println("Decifrato:\n" + dec);
} catch (IllegalArgumentException ex) {
System.out.println("> Errore: Assicurati di inserire un numero valido.");
}
}
case 2 -> {
// MODALITÀ STRINGA
System.out.print("Inserisci il testo da cifrare: ");
String input = scanner.nextLine();
System.out.println("> Cifratura in corso...");
String cifrato = RSA.encrypt(input, chiavi.e(), chiavi.n());
if (cifrato != null && !cifrato.isEmpty()) {
// 2. SOLO PER LA STAMPA: nascondiamo il binario convertendolo in Base64
String base64 = java.util.Base64.getEncoder().encodeToString(cifrato.getBytes());
System.out.println("Cifrato (Base64):\n" + base64);
}
System.out.println("\n> Decifratura in corso...");
String dec = RSA.decrypt(cifrato, chiavi.d(), chiavi.n());
System.out.println("Decifrato:\n" + dec);
}
case 3 -> {
// RIGENERA CHIAVI
dimChiave = scegliDimensioneChiave(scanner);
System.out.println("\n> Generazione delle chiavi in corso...");
chiavi = RSA.defkeys(dimChiave / 2);
System.out.println("> Chiavi rigenerate con successo!");
}
case 0 -> {
continua = false;
System.out.println("Chiusura del motore RSA. Alla prossima!");
}
default -> System.out.println("> Scelta non valida, riprova.");
}
}
scanner.close();
}
}

View File

@@ -1,93 +1,93 @@
package com.crypto;
import java.math.BigInteger;
public class RSA {
// Struttura che rappresenta il mazzo di chiavi che viene generato con la
// funzione defkeys()
public record RSAkeys(BigInteger n, BigInteger e, BigInteger d) {}
static RSAkeys defkeys(int primesize) {
// Generiamo i numeri primi p e q, con la size scelta dall'utente
BigInteger p = Utilities.GenPrime(primesize);
BigInteger q = Utilities.GenPrime(primesize);
// Rigeneriamo q se p e q sono uguali (just in case)
while (p.equals(q)) {
q = Utilities.GenPrime(primesize);
}
// Calcoliamo n come prodotto pq
BigInteger n = p.multiply(q);
// Calcoliamo la funzione di Eulero phi (o m)
BigInteger phi = (p.subtract(BigInteger.ONE)).multiply((q.subtract(BigInteger.ONE)));
// Calcoliamo la chiave pubblica e, rendendola prima rispetto a phi
BigInteger e = Utilities.CalculateE(phi);
// Stampa i risultati per il debug
System.out.println("\n--- RISULTATI GENERAZIONE ---");
System.out.println("Bit di p generato: " + p);
System.out.println("Bit di q generato: " + q);
System.out.println("Bit del modulo n: " + n);
System.out.println("Bit di phi generato: " + phi);
System.out.println("Bit del modulo e: " + e);
// Calcoliamo la chiave privata d (o k)
BigInteger d = e.modInverse(phi);
return new RSAkeys(n, e, d);
}
// ---------------------- Encrypting e Decrypting di valori numerici ----------------------------------
static BigInteger encrypt(BigInteger m, BigInteger e, BigInteger n) {
// Controllo vitale: m deve essere positivo e minore di n
if (m.compareTo(BigInteger.ZERO) < 0 || m.compareTo(n) >= 0) {
throw new IllegalArgumentException(
"Il messaggio deve essere positivo e minore del modulo n! - Cifratura annullata");
}
// Cifriamo con i nostri parametri kpb(e,n)
return m.modPow(e, n);
}
static BigInteger decrypt(BigInteger c, BigInteger d, BigInteger n) {
// Decifriamo con i nostri parametri kpb(e,n)
return c.modPow(d, n);
}
// ---------------- Encrypting e Decrypting di valori alfanumerici ---------------------------
static String encrypt(String input, BigInteger e, BigInteger n) {
// Calcoliamo la lunghezza dei blocchi g e la approssimiamo per difetto
// basta contare i bit necessari per rappresentare n e poi fare - 1 perchè non ci serve la precisione
int g = n.bitLength() - 1;
if (g == 8)
g = 7;
// Conversione da stringhe a bytes( ASCII ma in decimale !)
byte[] m = input.getBytes();
// Conversione in Binario e unificazione in un unica stringa
String data = Utilities.BytestoBin(m);
// Divisione del messaggio e cifratura
String res = Utilities.DivideetImpera(data,g,e,n);
return res;
}
static String decrypt(String m, BigInteger d, BigInteger n) {
// Calcolo di z
int z = n.bitLength();
if (n.and(n.subtract(BigInteger.ONE)).equals(BigInteger.ZERO))
z--; // n è una potenza esatta di 2, togli 1
// Calcolo di g
int g = n.bitLength() - 1;
if (g == 8)
g = 7;
String res = Utilities.ImperaetDivide(m, z, g, d, n);
return res.toString();
}
package com.crypto;
import java.math.BigInteger;
public class RSA {
// Struttura che rappresenta il mazzo di chiavi che viene generato con la
// funzione defkeys()
public record RSAkeys(BigInteger n, BigInteger e, BigInteger d) {}
static RSAkeys defkeys(int primesize) {
// Generiamo i numeri primi p e q, con la size scelta dall'utente
BigInteger p = Utilities.GenPrime(primesize);
BigInteger q = Utilities.GenPrime(primesize);
// Rigeneriamo q se p e q sono uguali (just in case)
while (p.equals(q)) {
q = Utilities.GenPrime(primesize);
}
// Calcoliamo n come prodotto pq
BigInteger n = p.multiply(q);
// Calcoliamo la funzione di Eulero phi (o m)
BigInteger phi = (p.subtract(BigInteger.ONE)).multiply((q.subtract(BigInteger.ONE)));
// Calcoliamo la chiave pubblica e, rendendola prima rispetto a phi
BigInteger e = Utilities.CalculateE(phi);
// Stampa i risultati per il debug
System.out.println("\n--- RISULTATI GENERAZIONE ---");
System.out.println("Bit di p generato: " + p);
System.out.println("Bit di q generato: " + q);
System.out.println("Bit del modulo n: " + n);
System.out.println("Bit di phi generato: " + phi);
System.out.println("Bit del modulo e: " + e);
// Calcoliamo la chiave privata d (o k)
BigInteger d = e.modInverse(phi);
return new RSAkeys(n, e, d);
}
// ---------------------- Encrypting e Decrypting di valori numerici ----------------------------------
static BigInteger encrypt(BigInteger m, BigInteger e, BigInteger n) {
// Controllo vitale: m deve essere positivo e minore di n
if (m.compareTo(BigInteger.ZERO) < 0 || m.compareTo(n) >= 0) {
throw new IllegalArgumentException(
"Il messaggio deve essere positivo e minore del modulo n! - Cifratura annullata");
}
// Cifriamo con i nostri parametri kpb(e,n)
return m.modPow(e, n);
}
static BigInteger decrypt(BigInteger c, BigInteger d, BigInteger n) {
// Decifriamo con i nostri parametri kpb(e,n)
return c.modPow(d, n);
}
// ---------------- Encrypting e Decrypting di valori alfanumerici ---------------------------
static String encrypt(String input, BigInteger e, BigInteger n) {
// Calcoliamo la lunghezza dei blocchi g e la approssimiamo per difetto
// basta contare i bit necessari per rappresentare n e poi fare - 1 perchè non ci serve la precisione
int g = n.bitLength() - 1;
if (g == 8)
g = 7;
// Conversione da stringhe a bytes( ASCII ma in decimale !)
byte[] m = input.getBytes();
// Conversione in Binario e unificazione in un unica stringa
String data = Utilities.BytestoBin(m);
// Divisione del messaggio e cifratura
String res = Utilities.DivideetImpera(data,g,e,n);
return res;
}
static String decrypt(String m, BigInteger d, BigInteger n) {
// Calcolo di z
int z = n.bitLength();
if (n.and(n.subtract(BigInteger.ONE)).equals(BigInteger.ZERO))
z--; // n è una potenza esatta di 2, togli 1
// Calcolo di g
int g = n.bitLength() - 1;
if (g == 8)
g = 7;
String res = Utilities.ImperaetDivide(m, z, g, d, n);
return res.toString();
}
}

View File

@@ -1,62 +1,62 @@
package com.crypto;
import io.javalin.Javalin;
public class Seal {
// Il mazzo di chiavi !!
public static RSA.RSAkeys keys;
public static void main(String[] args) {
// Avvio del server web
Javalin app = Javalin.create(config -> {
config.staticFiles.add("/get");
}).start(8080);
System.out.println("⏳ Generazione chiavi RSA per il server web in corso...");
// Cifratura con Cifrario di Cesare
app.post("/seal/caesar/encrypt", ctx -> {
}
);
// Decifratura con Cifrario di Vigenere
app.post("/seal/vigenere/encrypt", ctx -> {
}
);
// Cifratura con RSA
app.post("/seal/rsa/encrypt", ctx -> {
// Legge i dati nel body dalla richiesta
Richiesta req = ctx.bodyAsClass(Richiesta.class);
keys = RSA.defkeys(req.keysize / 2);
String ciphertext = RSA.encrypt(req.text,keys.e(), keys.n());
ctx.result(ciphertext);
});
// Decifratura con RSA
app.post("/seal/rsa/decrypt", ctx -> {
// Legge i dati nel body dalla richiesta
Richiesta req = ctx.bodyAsClass(Richiesta.class);
// Usa il metodo RSA per cifrare
String plaintext = RSA.decrypt(req.text, keys.d(), keys.n());
// Restituisce il risultato della cifratura
ctx.result(plaintext.replaceAll("\\\\u0000", ""));
});
}
}
// Classe utilizzata per tradurre il JSON - Rappresenta l'oggetto richiesta
class Richiesta {
public int keysize;
public String text;
// Costruttore della richiesta
public Richiesta() {}
package com.crypto;
import io.javalin.Javalin;
public class Seal {
// Il mazzo di chiavi !!
public static RSA.RSAkeys keys;
public static void main(String[] args) {
// Avvio del server web
Javalin app = Javalin.create(config -> {
config.staticFiles.add("/get");
}).start(8080);
System.out.println("⏳ Generazione chiavi RSA per il server web in corso...");
// Cifratura con Cifrario di Cesare
app.post("/seal/caesar/encrypt", ctx -> {
}
);
// Decifratura con Cifrario di Vigenere
app.post("/seal/vigenere/encrypt", ctx -> {
}
);
// Cifratura con RSA
app.post("/seal/rsa/encrypt", ctx -> {
// Legge i dati nel body dalla richiesta
Richiesta req = ctx.bodyAsClass(Richiesta.class);
keys = RSA.defkeys(req.keysize / 2);
String ciphertext = RSA.encrypt(req.text,keys.e(), keys.n());
ctx.result(ciphertext);
});
// Decifratura con RSA
app.post("/seal/rsa/decrypt", ctx -> {
// Legge i dati nel body dalla richiesta
Richiesta req = ctx.bodyAsClass(Richiesta.class);
// Usa il metodo RSA per cifrare
String plaintext = RSA.decrypt(req.text, keys.d(), keys.n());
// Restituisce il risultato della cifratura
ctx.result(plaintext.replaceAll("\\\\u0000", ""));
});
}
}
// Classe utilizzata per tradurre il JSON - Rappresenta l'oggetto richiesta
class Richiesta {
public int keysize;
public String text;
// Costruttore della richiesta
public Richiesta() {}
}

View File

@@ -1,116 +1,116 @@
package com.crypto;
import java.math.BigInteger;
import java.security.SecureRandom;
public class Utilities {
static BigInteger GenPrime(int primesize) {
// 0. Inizializza il generatore crittograficamente sicuro di numeri casuali
SecureRandom sr = new SecureRandom();
// 1. Definizione della soglia di precisione
int precision = 100;
// Stampa di attesa
System.out.println("Generazione dei numeri primi in corso... (potrebbe richiedere qualche istante)");
// 2. Generazione della chiave
BigInteger prime = new BigInteger(primesize, precision, sr);
return prime;
}
// Algoritmo visto in classe rimodellato per java
static BigInteger ModExp(BigInteger a, BigInteger b, BigInteger n) {
BigInteger result = BigInteger.valueOf(1);
a = a.mod(n);
while (b.compareTo(BigInteger.ZERO) > 0) {
// Se b è dispari
if (b.testBit(0)) {
result = result.multiply(a).mod(n);
}
a = (a.multiply(a)).mod(n);
// Dividiamo l'esponente per 2 spostando i bit (pare che sia più rapido in
// questo modo)
b = b.shiftRight(1);
}
return result;
}
static BigInteger CalculateE(BigInteger phi) {
BigInteger e = BigInteger.valueOf(65537);
// Finchè il GCD (MCD) non è esattamente uguale a uno
while (!(e.gcd(phi).equals(BigInteger.ONE))) {
e = e.add(BigInteger.valueOf(7));
}
return e;
}
public static String BytestoBin(byte[] m) {
StringBuilder sr = new StringBuilder();
for (byte b : m) {
// %8s significa stringa di 8 bit con eventuale padding a sinistra
// b viene messo in and con 0xFF che serve per forzare valori positivi
// il replace aggiunge il padding di zeri al posto degli spazi
sr.append(String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'));
}
return sr.toString();
}
// Converte i valori cifrati in binario e aggiunge il padding a sinistra fino a
// raggiungere il valore z
public static String BigIntToBin(BigInteger val, int g) {
String bin = val.toString(2);
StringBuilder sb = new StringBuilder();
// aggiungi zeri a sinistra fino a g
for (int i = bin.length(); i < g; i++) {
sb.append('0');
}
sb.append(bin);
return sb.toString();
}
// Divisione in blocchi e applicazione dell'algoritmo visto in classe per la cifratura
public static String DivideetImpera(String data, int g, BigInteger e, BigInteger n) {
StringBuilder res = new StringBuilder();
int i;
// Calcolo di z
int z = n.bitLength();
if (n.and(n.subtract(BigInteger.ONE)).equals(BigInteger.ZERO))
z--; // n è una potenza esatta di 2, togli 1
for (i = 0; (i + g) <= data.length(); i += g) {
String block = data.substring(i, i + g);// prendo il blocco
BigInteger val = new BigInteger(block, 2);// converto in binario
res.append(BigIntToBin(val.modPow(e, n), z));
}
if (i < data.length()) {
String b = data.substring(i, data.length());
while (g != b.length()) {
b += '0';
}
BigInteger val = new BigInteger(b, 2);// converto in binario
res.append(BigIntToBin(val.modPow(e, n), z));
}
return res.toString();
}
// Divisione in blocchi e applicazione dell'algoritmo visto in classe per la decifratura
public static String ImperaetDivide(String data, int z,int g, BigInteger e, BigInteger n) {
StringBuilder res = new StringBuilder();
for (int i = 0; (i + z) <= data.length(); i += z) {
BigInteger val = new BigInteger(data.substring(i, i + z), 2);
res.append(BigIntToBin(val.modPow(e, n), g));
}
StringBuilder testo = new StringBuilder();
for (int i = 0; i + 8 <= res.length(); i += 8) {
String block = res.substring(i, i + 8);
int ascii = Integer.parseInt(block, 2);
testo.append((char) ascii);
}
return testo.toString();
}
package com.crypto;
import java.math.BigInteger;
import java.security.SecureRandom;
public class Utilities {
static BigInteger GenPrime(int primesize) {
// 0. Inizializza il generatore crittograficamente sicuro di numeri casuali
SecureRandom sr = new SecureRandom();
// 1. Definizione della soglia di precisione
int precision = 100;
// Stampa di attesa
System.out.println("Generazione dei numeri primi in corso... (potrebbe richiedere qualche istante)");
// 2. Generazione della chiave
BigInteger prime = new BigInteger(primesize, precision, sr);
return prime;
}
// Algoritmo visto in classe rimodellato per java
static BigInteger ModExp(BigInteger a, BigInteger b, BigInteger n) {
BigInteger result = BigInteger.valueOf(1);
a = a.mod(n);
while (b.compareTo(BigInteger.ZERO) > 0) {
// Se b è dispari
if (b.testBit(0)) {
result = result.multiply(a).mod(n);
}
a = (a.multiply(a)).mod(n);
// Dividiamo l'esponente per 2 spostando i bit (pare che sia più rapido in
// questo modo)
b = b.shiftRight(1);
}
return result;
}
static BigInteger CalculateE(BigInteger phi) {
BigInteger e = BigInteger.valueOf(65537);
// Finchè il GCD (MCD) non è esattamente uguale a uno
while (!(e.gcd(phi).equals(BigInteger.ONE))) {
e = e.add(BigInteger.valueOf(7));
}
return e;
}
public static String BytestoBin(byte[] m) {
StringBuilder sr = new StringBuilder();
for (byte b : m) {
// %8s significa stringa di 8 bit con eventuale padding a sinistra
// b viene messo in and con 0xFF che serve per forzare valori positivi
// il replace aggiunge il padding di zeri al posto degli spazi
sr.append(String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'));
}
return sr.toString();
}
// Converte i valori cifrati in binario e aggiunge il padding a sinistra fino a
// raggiungere il valore z
public static String BigIntToBin(BigInteger val, int g) {
String bin = val.toString(2);
StringBuilder sb = new StringBuilder();
// aggiungi zeri a sinistra fino a g
for (int i = bin.length(); i < g; i++) {
sb.append('0');
}
sb.append(bin);
return sb.toString();
}
// Divisione in blocchi e applicazione dell'algoritmo visto in classe per la cifratura
public static String DivideetImpera(String data, int g, BigInteger e, BigInteger n) {
StringBuilder res = new StringBuilder();
int i;
// Calcolo di z
int z = n.bitLength();
if (n.and(n.subtract(BigInteger.ONE)).equals(BigInteger.ZERO))
z--; // n è una potenza esatta di 2, togli 1
for (i = 0; (i + g) <= data.length(); i += g) {
String block = data.substring(i, i + g);// prendo il blocco
BigInteger val = new BigInteger(block, 2);// converto in binario
res.append(BigIntToBin(val.modPow(e, n), z));
}
if (i < data.length()) {
String b = data.substring(i, data.length());
while (g != b.length()) {
b += '0';
}
BigInteger val = new BigInteger(b, 2);// converto in binario
res.append(BigIntToBin(val.modPow(e, n), z));
}
return res.toString();
}
// Divisione in blocchi e applicazione dell'algoritmo visto in classe per la decifratura
public static String ImperaetDivide(String data, int z,int g, BigInteger e, BigInteger n) {
StringBuilder res = new StringBuilder();
for (int i = 0; (i + z) <= data.length(); i += z) {
BigInteger val = new BigInteger(data.substring(i, i + z), 2);
res.append(BigIntToBin(val.modPow(e, n), g));
}
StringBuilder testo = new StringBuilder();
for (int i = 0; i + 8 <= res.length(); i += 8) {
String block = res.substring(i, i + 8);
int ascii = Integer.parseInt(block, 2);
testo.append((char) ascii);
}
return testo.toString();
}
}

36
src/pom.xml Normal file
View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.crypto</groupId>
<artifactId>cryptoseals</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>6.1.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,77 +1,77 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>CryptoSeals - Cesare</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navbar">
<a href="index.html" class="nav-brand">
<img src="logo.png" alt="🦭" onerror="this.style.display='none'; this.nextElementSibling.style.display='inline';">
<span style="display:none;">🦭</span> CryptoSeals
</a>
<ul class="nav-links">
<li><a href="rsa.html">Algoritmo RSA</a></li>
<li><a href="cesare.html" style="color: #3498db;">Cesare</a></li> <li><a href="vigenere.html">Vigenère</a></li>
<li><a href="storia.html">La Storia</a></li>
<li><a href="team.html">Il Team</a></li>
</ul>
</nav>
<div class="container">
<h1>Cifrario di Cesare</h1>
<p class="descrizione">Sposta le lettere dell'alfabeto di un numero fisso di posizioni. Semplice, storico, ma efficace per messaggi veloci.</p>
<div class="crypto-box">
<label>Chiave (Numero di spostamento):</label>
<input type="number" id="chiaveCesare" value="3" placeholder="Es. 3" style="width: 100%; padding: 12px; margin-top: 5px; margin-bottom: 15px; border-radius: 5px; border: 1px solid #ccc;">
<label>Testo in chiaro:</label>
<textarea id="testoInput" placeholder="Scrivi qui il messaggio da cifrare..."></textarea>
<button onclick="cifraCesare()">🔒 Cifra con Cesare</button>
<label style="display:block; margin-top: 25px;">Testo Cifrato:</label>
<textarea id="testoOutput" placeholder="Il risultato cifrato apparirà qui..."></textarea>
<button class="btn-green" onclick="decifraCesare()">🔓 Decifra in chiaro</button>
<label style="display:block; margin-top: 25px;">Risultato decifrato:</label>
<textarea id="testoDecifrato" readonly placeholder="Il messaggio originale tornerà qui..."></textarea>
</div>
</div>
<script>
async function cifraCesare() {
const input = document.getElementById("testoInput").value;
const chiave = document.getElementById("chiaveCesare").value;
if(!input) return alert("Inserisci del testo!");
try {
const risposta = await fetch("http://localhost:8080/api/cesare/cifra", {
method: "POST", headers: { "Content-Type": "application/json" },
// Invia il testo e la CHIAVE (convertita in numero) al server
body: JSON.stringify({ testo: input, chiave: parseInt(chiave) })
});
document.getElementById("testoOutput").value = await risposta.text();
} catch (e) { alert("Errore di connessione con le API di Cesare!"); }
}
async function decifraCesare() {
const inputCifrato = document.getElementById("testoOutput").value;
const chiave = document.getElementById("chiaveCesare").value;
if(!inputCifrato) return alert("Nessun testo da decifrare!");
try {
const risposta = await fetch("http://localhost:8080/api/cesare/decifra", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ testo: inputCifrato, chiave: parseInt(chiave) })
});
document.getElementById("testoDecifrato").value = await risposta.text();
} catch (e) { alert("Errore di connessione!"); }
}
</script>
</body>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>CryptoSeals - Cesare</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navbar">
<a href="index.html" class="nav-brand">
<img src="logo.png" alt="🦭" onerror="this.style.display='none'; this.nextElementSibling.style.display='inline';">
<span style="display:none;">🦭</span> CryptoSeals
</a>
<ul class="nav-links">
<li><a href="rsa.html">Algoritmo RSA</a></li>
<li><a href="cesare.html" style="color: #3498db;">Cesare</a></li> <li><a href="vigenere.html">Vigenère</a></li>
<li><a href="storia.html">La Storia</a></li>
<li><a href="team.html">Il Team</a></li>
</ul>
</nav>
<div class="container">
<h1>Cifrario di Cesare</h1>
<p class="descrizione">Sposta le lettere dell'alfabeto di un numero fisso di posizioni. Semplice, storico, ma efficace per messaggi veloci.</p>
<div class="crypto-box">
<label>Chiave (Numero di spostamento):</label>
<input type="number" id="chiaveCesare" value="3" placeholder="Es. 3" style="width: 100%; padding: 12px; margin-top: 5px; margin-bottom: 15px; border-radius: 5px; border: 1px solid #ccc;">
<label>Testo in chiaro:</label>
<textarea id="testoInput" placeholder="Scrivi qui il messaggio da cifrare..."></textarea>
<button onclick="cifraCesare()">🔒 Cifra con Cesare</button>
<label style="display:block; margin-top: 25px;">Testo Cifrato:</label>
<textarea id="testoOutput" placeholder="Il risultato cifrato apparirà qui..."></textarea>
<button class="btn-green" onclick="decifraCesare()">🔓 Decifra in chiaro</button>
<label style="display:block; margin-top: 25px;">Risultato decifrato:</label>
<textarea id="testoDecifrato" readonly placeholder="Il messaggio originale tornerà qui..."></textarea>
</div>
</div>
<script>
async function cifraCesare() {
const input = document.getElementById("testoInput").value;
const chiave = document.getElementById("chiaveCesare").value;
if(!input) return alert("Inserisci del testo!");
try {
const risposta = await fetch("http://localhost:8080/api/cesare/cifra", {
method: "POST", headers: { "Content-Type": "application/json" },
// Invia il testo e la CHIAVE (convertita in numero) al server
body: JSON.stringify({ testo: input, chiave: parseInt(chiave) })
});
document.getElementById("testoOutput").value = await risposta.text();
} catch (e) { alert("Errore di connessione con le API di Cesare!"); }
}
async function decifraCesare() {
const inputCifrato = document.getElementById("testoOutput").value;
const chiave = document.getElementById("chiaveCesare").value;
if(!inputCifrato) return alert("Nessun testo da decifrare!");
try {
const risposta = await fetch("http://localhost:8080/api/cesare/decifra", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ testo: inputCifrato, chiave: parseInt(chiave) })
});
document.getElementById("testoDecifrato").value = await risposta.text();
} catch (e) { alert("Errore di connessione!"); }
}
</script>
</body>
</html>

View File

@@ -0,0 +1,157 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CryptoSeals - Motore RSA</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navbar">
<a href="index.html" class="nav-brand">
<img src="seal1.png" height="50" alt="🦭" onerror="this.src='https://cdn-icons-png.flaticon.com/512/3063/3063126.png';">
CryptoSeals
</a>
<div class="menu-toggle" onclick="toggleMenu()">
<i class="fa-solid fa-bars"></i>
</div>
<ul class="nav-links" id="nav-links">
<li><a href="rsa.html" class="active"><i class="fa-solid fa-key"></i> RSA</a></li>
<li><a href="cesare.html"><i class="fa-solid fa-arrow-right-arrow-left"></i> Cesare</a></li>
<li><a href="vigenere.html"><i class="fa-solid fa-table"></i> Vigenère</a></li>
<li><a href="team.html"><i class="fa-solid fa-users"></i> Il Team</a></li>
</ul>
</nav>
<div class="container">
<h1>Motore RSA</h1>
<p class="descrizione">Cifra e decifra i tuoi messaggi con lo standard di sicurezza a chiave pubblica. Scegli la dimensione delle chiavi, scrivi e lascia fare alle foche.</p>
<div class="crypto-box">
<label><i class="fa-solid fa-ruler-horizontal"></i> Dimensione Chiave RSA</label>
<select id="keysize" style="margin-top: 5px; margin-bottom: 20px;">
<option value="512">512 bit (Solo didattico - Veloce)</option>
<option value="1024" selected>1024 bit (Test - Bilanciato)</option>
<option value="2048">2048 bit (Standard - Lenta da generare ⏳)</option>
<option value="4096">4096 bit (Alta sicurezza - Molto lenta ⏳⏳)</option>
</select>
<div class="crypto-columns">
<div class="crypto-col">
<label><i class="fa-solid fa-pen"></i> Testo in chiaro</label>
<textarea id="plaintext" placeholder="Scrivi il messaggio segreto che vuoi proteggere..."></textarea>
<button id="btn-encrypt" onclick="encrypt()"><i class="fa-solid fa-lock"></i> Cifra il messaggio</button>
</div>
<div class="crypto-col">
<label><i class="fa-solid fa-barcode"></i> Testo Cifrato (Base64)</label>
<textarea id="ciphertext" placeholder="Il testo protetto apparirà qui..."></textarea>
<button id="btn-decrypt" class="btn-green" onclick="decrypt()"><i class="fa-solid fa-unlock-keyhole"></i> Decifra il messaggio</button>
</div>
</div>
<div style="margin-top: 35px;">
<label><i class="fa-solid fa-check-double"></i> Risultato finale decifrato</label>
<textarea id="decodedtext" readonly placeholder="Il messaggio originale apparirà qui dopo la decifratura..." style="height: 100px; background-color: rgba(16, 185, 129, 0.1); border-color: var(--accent-green); color: var(--accent-green);"></textarea>
</div>
</div>
</div>
<script>
function toggleMenu() {
document.getElementById("nav-links").classList.toggle("active");
}
// Configurazione globale per SweetAlert2 in tema dark
const Toast = Swal.mixin({
background: '#1f2937',
color: '#f3f4f6',
confirmButtonColor: '#10b981'
});
async function encrypt() {
const plaintext = document.getElementById("plaintext").value;
const size = document.getElementById("keysize").value;
const btn = document.getElementById("btn-encrypt");
if(!plaintext) {
return Toast.fire({ icon: "warning", title: "Attenzione", text: "Per favore, inserisci del testo da cifrare." });
}
// Stato di caricamento UI
btn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Cifratura in corso...';
btn.disabled = true;
try {
const res = await fetch("http://localhost:8080/seal/rsa/encrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: plaintext, keysize: parseInt(size) })
});
if(!res.ok) throw new Error("Errore Server");
document.getElementById("ciphertext").value = await res.text();
Toast.fire({
icon: 'success',
title: 'Completato!',
text: 'Il messaggio è stato cifrato con successo.',
timer: 2000,
showConfirmButton: false
});
} catch (e) {
Toast.fire({ icon: "error", title: "Errore di connessione", text: "Impossibile connettersi al server Javalin. Controlla che sia avviato!" });
} finally {
// Ripristino bottone
btn.innerHTML = '<i class="fa-solid fa-lock"></i> Cifra il messaggio';
btn.disabled = false;
}
}
async function decrypt() {
const input = document.getElementById("ciphertext").value;
const btn = document.getElementById("btn-decrypt");
if(!input) {
return Toast.fire({ icon: "warning", title: "Attenzione", text: "Non c'è nessun testo cifrato da decodificare." });
}
// Stato di caricamento UI
btn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Decifratura in corso...';
btn.disabled = true;
try {
const res = await fetch("http://localhost:8080/seal/rsa/decrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: input })
});
if(!res.ok) throw new Error("Errore Server");
document.getElementById("decodedtext").value = await res.text();
Toast.fire({
icon: 'success',
title: 'Decifrato!',
text: 'Messaggio originale recuperato.',
timer: 2000,
showConfirmButton: false
});
} catch (e) {
Toast.fire({ icon: "error", title: "Errore", text: "Impossibile decifrare. Il testo potrebbe essere corrotto o il server offline." });
} finally {
// Ripristino bottone
btn.innerHTML = '<i class="fa-solid fa-unlock-keyhole"></i> Decifra il messaggio';
btn.disabled = false;
}
}
</script>
</body>
</html>

View File

@@ -1,95 +1,95 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>CryptoSeals - RSA</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navbar">
<a href="index.html" class="nav-brand">
<span><img src="seal1.png" height="80"onerror="this.style.display='none'; this.nextElementSibling.style.display='inline';"></span> CryptoSeals
</a>
<ul class="nav-links">
<li><a href="rsa.html" class="active">Algoritmo RSA</a></li>
<li><a href="cesare.html">Cesare</a></li>
<li><a href="vigenere.html">Vigenère</a></li>
<li><a href="storia.html">La Storia</a></li>
<li><a href="team.html">Il Team</a></li>
</ul>
</nav>
<div class="container">
<h1>Motore RSA</h1>
<p class="descrizione">Cifra e decifra i tuoi messaggi con lo standard di sicurezza a chiave pubblica. Scegli la dimensione delle chiavi, scrivi e lascia fare alle foche.</p>
<div class="crypto-box">
<label>Dimensione Chiave RSA</label>
<select id="keysize">
<option value="512">512 bit (Solo didattico - Veloce)</option>
<option value="1024" selected>1024 bit (Test - Bilanciato)</option>
<option value="2048">2048 bit (Standard - Lenta da generare ⏳)</option>
<option value="4096">4096 bit (Alta sicurezza - Molto lenta ⏳⏳)</option>
</select>
<div class="crypto-columns">
<div class="crypto-col">
<label>Testo in chiaro</label>
<textarea id="plaintext" class="pulse-textarea" placeholder="Scrivi il messaggio segreto che vuoi proteggere..."></textarea>
<button onclick="encrypt()">🔒 Cifra il messaggio</button>
</div>
<div class="crypto-col">
<label>Testo Cifrato (Base64)</label>
<textarea id="ciphertext" placeholder="Il testo protetto apparirà qui..."></textarea>
<button class="btn-green" onclick="decrypt()">🔓 Decifra il messaggio</button>
</div>
</div>
<div style="margin-top: 35px;">
<label>Risultato finale decifrato</label>
<textarea id="decodedtext" readonly placeholder="Il messaggio originale apparirà qui dopo la decifratura..." style="height: 100px; background-color: #0b0f19; border-color: rgba(16, 185, 129, 0.3); color: #10b981;"></textarea>
</div>
</div>
</div>
<script>
async function encrypt() {
const plaintext = document.getElementById("plaintext").value;
const size = document.getElementById("keysize").value;
if(!plaintext) return alert("Per favore, inserisci del testo da cifrare.");
document.getElementById("ciphertext").value = "Le foche stanno cifrando... Attendere prego.";
try {
// NOTA: Controlla che la rotta nel tuo Java sia corretta (/seal/rsa/encrypt o /api/rsa/cifra)
const res = await fetch("http://localhost:8080/seal/rsa/encrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: plaintext, keysize: parseInt(size) })
});
document.getElementById("ciphertext").value = await res.text();
} catch (e) { alert("Impossibile connettersi al server Javalin."); }
}
async function decrypt() {
const input = document.getElementById("ciphertext").value;
if(!input) return alert("Non c'è nessun testo da decifrare.");
document.getElementById("decodedtext").value = "Decifratura in corso...";
try {
// NOTA: Controlla che la rotta nel tuo Java sia corretta (/seal/rsa/decrypt o /api/rsa/decifra)
const res = await fetch("http://localhost:8080/seal/rsa/decrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: input })
});
document.getElementById("decodedtext").value = await res.text();
} catch (e) { alert("Impossibile connettersi al server."); }
}
</script>
</body>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>CryptoSeals - RSA</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav class="navbar">
<a href="index.html" class="nav-brand">
<span><img src="seal1.png" height="80"onerror="this.style.display='none'; this.nextElementSibling.style.display='inline';"></span> CryptoSeals
</a>
<ul class="nav-links">
<li><a href="rsa.html" class="active">Algoritmo RSA</a></li>
<li><a href="cesare.html">Cesare</a></li>
<li><a href="vigenere.html">Vigenère</a></li>
<li><a href="storia.html">La Storia</a></li>
<li><a href="team.html">Il Team</a></li>
</ul>
</nav>
<div class="container">
<h1>Motore RSA</h1>
<p class="descrizione">Cifra e decifra i tuoi messaggi con lo standard di sicurezza a chiave pubblica. Scegli la dimensione delle chiavi, scrivi e lascia fare alle foche.</p>
<div class="crypto-box">
<label>Dimensione Chiave RSA</label>
<select id="keysize">
<option value="512">512 bit (Solo didattico - Veloce)</option>
<option value="1024" selected>1024 bit (Test - Bilanciato)</option>
<option value="2048">2048 bit (Standard - Lenta da generare ⏳)</option>
<option value="4096">4096 bit (Alta sicurezza - Molto lenta ⏳⏳)</option>
</select>
<div class="crypto-columns">
<div class="crypto-col">
<label>Testo in chiaro</label>
<textarea id="plaintext" class="pulse-textarea" placeholder="Scrivi il messaggio segreto che vuoi proteggere..."></textarea>
<button onclick="encrypt()">🔒 Cifra il messaggio</button>
</div>
<div class="crypto-col">
<label>Testo Cifrato (Base64)</label>
<textarea id="ciphertext" placeholder="Il testo protetto apparirà qui..."></textarea>
<button class="btn-green" onclick="decrypt()">🔓 Decifra il messaggio</button>
</div>
</div>
<div style="margin-top: 35px;">
<label>Risultato finale decifrato</label>
<textarea id="decodedtext" readonly placeholder="Il messaggio originale apparirà qui dopo la decifratura..." style="height: 100px; background-color: #0b0f19; border-color: rgba(16, 185, 129, 0.3); color: #10b981;"></textarea>
</div>
</div>
</div>
<script>
async function encrypt() {
const plaintext = document.getElementById("plaintext").value;
const size = document.getElementById("keysize").value;
if(!plaintext) return alert("Per favore, inserisci del testo da cifrare.");
document.getElementById("ciphertext").value = "Le foche stanno cifrando... Attendere prego.";
try {
// NOTA: Controlla che la rotta nel tuo Java sia corretta (/seal/rsa/encrypt o /api/rsa/cifra)
const res = await fetch("http://localhost:8080/seal/rsa/encrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: plaintext, keysize: parseInt(size) })
});
document.getElementById("ciphertext").value = await res.text();
} catch (e) { alert("Impossibile connettersi al server Javalin."); }
}
async function decrypt() {
const input = document.getElementById("ciphertext").value;
if(!input) return alert("Non c'è nessun testo da decifrare.");
document.getElementById("decodedtext").value = "Decifratura in corso...";
try {
// NOTA: Controlla che la rotta nel tuo Java sia corretta (/seal/rsa/decrypt o /api/rsa/decifra)
const res = await fetch("http://localhost:8080/seal/rsa/decrypt", {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: input })
});
document.getElementById("decodedtext").value = await res.text();
} catch (e) { alert("Impossibile connettersi al server."); }
}
</script>
</body>
</html>

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

238
src/resources/get/style.css Normal file
View File

@@ -0,0 +1,238 @@
/* --- IMPORTS --- */
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&family=Poppins:wght@300;400;600&display=swap');
/* --- VARIABILI GLOBALI --- */
:root {
--bg-dark: #0b0f19;
--accent-green: #10b981;
--accent-hover: #059669;
--text-main: #f3f4f6;
--glass-bg: rgba(17, 24, 39, 0.7);
--glass-border: rgba(255, 255, 255, 0.1);
}
/* --- BASE --- */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Poppins', sans-serif;
background: radial-gradient(circle at top right, #1f2937, var(--bg-dark));
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* --- NAVBAR (Glassmorphism) --- */
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 5%;
background: var(--glass-bg);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border-bottom: 1px solid var(--glass-border);
position: sticky;
top: 0;
z-index: 1000;
}
.nav-brand {
display: flex;
align-items: center;
gap: 15px;
font-size: 1.5rem;
font-weight: 600;
color: var(--text-main);
text-decoration: none;
}
.nav-brand img {
border-radius: 50%;
}
.nav-links {
list-style: none;
display: flex;
gap: 20px;
}
.nav-links a {
color: var(--text-main);
text-decoration: none;
font-weight: 400;
transition: color 0.3s ease;
}
.nav-links a:hover, .nav-links a.active {
color: var(--accent-green);
}
/* Menu Mobile */
.menu-toggle {
display: none;
font-size: 1.5rem;
cursor: pointer;
}
/* --- CONTENITORI --- */
.container {
flex: 1;
max-width: 1000px;
margin: 40px auto;
padding: 0 20px;
text-align: center;
}
h1 {
font-size: 2.5rem;
margin-bottom: 15px;
color: var(--accent-green);
}
.descrizione {
font-size: 1.1rem;
margin-bottom: 30px;
color: #9ca3af;
}
/* --- CRYPTO BOX (Glassmorphism) --- */
.crypto-box {
background: var(--glass-bg);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
border: 1px solid var(--glass-border);
border-radius: 15px;
padding: 30px;
text-align: left;
box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.crypto-columns {
display: flex;
gap: 20px;
margin-top: 20px;
}
.crypto-col {
flex: 1;
display: flex;
flex-direction: column;
gap: 10px;
}
/* --- FORMS & INPUTS --- */
label {
font-weight: 600;
font-size: 0.9rem;
color: var(--accent-green);
}
select, textarea {
width: 100%;
padding: 12px;
border-radius: 8px;
background: rgba(0, 0, 0, 0.3);
border: 1px solid var(--glass-border);
color: var(--text-main);
font-family: 'Poppins', sans-serif;
outline: none;
transition: border-color 0.3s;
}
select:focus, textarea:focus {
border-color: var(--accent-green);
}
/* Font Monospazio per il testo cifrato */
#ciphertext, #decodedtext {
font-family: 'Fira Code', monospace;
font-size: 0.9rem;
}
textarea {
resize: vertical;
min-height: 120px;
}
/* --- BOTTONI --- */
button {
padding: 12px;
border: none;
border-radius: 8px;
background-color: var(--accent-green);
color: white;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s, transform 0.1s;
font-family: 'Poppins', sans-serif;
display: flex;
justify-content: center;
align-items: center;
gap: 8px;
}
button:hover {
background-color: var(--accent-hover);
}
button:active {
transform: scale(0.98);
}
button:disabled {
background-color: #374151;
cursor: not-allowed;
}
.btn-green {
background-color: #3b82f6; /* Usiamo un blu per distinguere la decifratura */
}
.btn-green:hover {
background-color: #2563eb;
}
/* --- FOOTER --- */
footer {
text-align: center;
padding: 20px;
background: var(--bg-dark);
border-top: 1px solid var(--glass-border);
font-size: 0.9rem;
color: #6b7280;
}
footer a {
color: var(--accent-green);
text-decoration: none;
}
/* --- RESPONSIVE --- */
@media (max-width: 768px) {
.crypto-columns {
flex-direction: column;
}
.nav-links {
display: none;
flex-direction: column;
position: absolute;
top: 70px;
left: 0;
width: 100%;
background: var(--bg-dark);
padding: 20px 0;
text-align: center;
}
.nav-links.active {
display: flex;
}
.menu-toggle {
display: block;
}
}