This commit is contained in:
@@ -1,18 +1,13 @@
|
|||||||
package com.crypto;
|
package com.crypto;
|
||||||
import java.util.Scanner;
|
|
||||||
public class Caesar {
|
public class Caesar {
|
||||||
|
|
||||||
public static void encode(Scanner sc){
|
public static String encode(String plaintext, int key){
|
||||||
String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
||||||
System.out.println("Digita il testo in chiaro da cifrare:");
|
char encoded[] = plaintext.toCharArray();
|
||||||
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++){
|
for(int i = 0; i < plaintext.length(); i++){
|
||||||
encoded[i] = alphabet.charAt(alphabet.indexOf(encoded[i]) + key % 26);
|
encoded[i] = alphabet.charAt(alphabet.indexOf(encoded[i]) + key % 26);
|
||||||
}
|
}
|
||||||
System.out.println(encoded);
|
return encoded.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ public class Seal {
|
|||||||
|
|
||||||
// Decifratura con Cifrario di Vigenere
|
// Decifratura con Cifrario di Vigenere
|
||||||
app.post("/seal/vigenere/encrypt", ctx -> {
|
app.post("/seal/vigenere/encrypt", ctx -> {
|
||||||
|
RichiestaCesare req = ctx.bodyAsClass(RichiestaCesare.class);
|
||||||
|
String ciphertext = Caesar.encode(req.plaintext,req.key);
|
||||||
|
ctx.result(ciphertext);
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
@@ -31,7 +33,7 @@ public class Seal {
|
|||||||
// Cifratura con RSA
|
// Cifratura con RSA
|
||||||
app.post("/seal/rsa/encrypt", ctx -> {
|
app.post("/seal/rsa/encrypt", ctx -> {
|
||||||
// Legge i dati nel body dalla richiesta
|
// Legge i dati nel body dalla richiesta
|
||||||
Richiesta req = ctx.bodyAsClass(Richiesta.class);
|
RichiestaRSA req = ctx.bodyAsClass(RichiestaRSA.class);
|
||||||
RSA.RSAkeys keys = RSA.defkeys(req.keysize / 2);
|
RSA.RSAkeys keys = RSA.defkeys(req.keysize / 2);
|
||||||
String ciphertext = RSA.encrypt(req.text,keys.e(), keys.n());
|
String ciphertext = RSA.encrypt(req.text,keys.e(), keys.n());
|
||||||
ctx.result("{\"ciphertext\":\""+ciphertext+"\",\"keys\":{\"d\":\"" + keys.d().toString() + "\",\"n\":\"" + keys.n().toString() + "\"}}");
|
ctx.result("{\"ciphertext\":\""+ciphertext+"\",\"keys\":{\"d\":\"" + keys.d().toString() + "\",\"n\":\"" + keys.n().toString() + "\"}}");
|
||||||
@@ -40,7 +42,7 @@ public class Seal {
|
|||||||
// Decifratura con RSA
|
// Decifratura con RSA
|
||||||
app.post("/seal/rsa/decrypt", ctx -> {
|
app.post("/seal/rsa/decrypt", ctx -> {
|
||||||
// Legge i dati nel body dalla richiesta
|
// Legge i dati nel body dalla richiesta
|
||||||
Richiesta req = ctx.bodyAsClass(Richiesta.class);
|
RichiestaRSA req = ctx.bodyAsClass(RichiestaRSA.class);
|
||||||
|
|
||||||
BigInteger d = new BigInteger(req.d);
|
BigInteger d = new BigInteger(req.d);
|
||||||
BigInteger n = new BigInteger(req.n);
|
BigInteger n = new BigInteger(req.n);
|
||||||
@@ -49,18 +51,25 @@ public class Seal {
|
|||||||
String plaintext = RSA.decrypt(req.text, d, n);
|
String plaintext = RSA.decrypt(req.text, d, n);
|
||||||
|
|
||||||
// Restituisce il risultato della cifratura
|
// Restituisce il risultato della cifratura
|
||||||
ctx.result(plaintext.replaceAll("\\\\u0000/g", ""));
|
ctx.result(plaintext.replace("\u0000", "").trim());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Classe utilizzata per tradurre il JSON - Rappresenta l'oggetto richiesta
|
// Classi utilizzate per tradurre il JSON - Rappresenta l'oggetto richiesta
|
||||||
class Richiesta {
|
class RichiestaCesare {
|
||||||
|
public int key;
|
||||||
|
public String plaintext;
|
||||||
|
|
||||||
|
// Costruttore della richiesta
|
||||||
|
}
|
||||||
|
|
||||||
|
class RichiestaRSA {
|
||||||
public int keysize;
|
public int keysize;
|
||||||
public String text;
|
public String text;
|
||||||
public String d;
|
public String d;
|
||||||
public String n;
|
public String n;
|
||||||
|
|
||||||
// Costruttore della richiesta
|
// Costruttore della richiesta
|
||||||
public Richiesta() {}
|
public RichiestaRSA() {}
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,16 @@ body {
|
|||||||
|
|
||||||
.nav-brand img {
|
.nav-brand img {
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
|
height: 40px;
|
||||||
|
width: 80px;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-brand img:hover {
|
||||||
|
object-fit: fill;
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: -10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-links {
|
.nav-links {
|
||||||
|
|||||||
Reference in New Issue
Block a user