[:it]
Questo programma, sviluppato da Alessandro Angelone studente indirizzo informatica e telecomunicazione, implementa il cifrario di Cesare:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Crypter {
private static final int matrix = 3;
private String word;
private String cryptedString;
private void cryptString() {
StringBuilder crypted = new StringBuilder(word);
for (int i = 0; i < crypted.length(); i++)
crypted.setCharAt(i, (char) ((int) (word.charAt(i)) + matrix));
cryptedString = crypted.toString();
}
public Crypter() {
word = null;
}
public Crypter(String word) {
this.word = word;
cryptString();
}
public void setWord(String word) {
this.word = word;
cryptString();
}
public String getCryptedString() {
return cryptedString;
}
public static String decryptString(String word) {
StringBuilder decrypted = new StringBuilder(word);
for (int i = 0; i < decrypted.length(); i++)
decrypted.setCharAt(i, (char) ((int) (decrypted.charAt(i)) – matrix));
return decrypted.toString();
}
public String decryptString() {
StringBuilder decrypted = new StringBuilder(cryptedString);
for (int i = 0; i < decrypted.length(); i++)
decrypted.setCharAt(i, (char) ((int) (decrypted.charAt(i)) – matrix));
return decrypted.toString();
}
}
public class cifrario_sostituzione {
public static void main(String[] args) {
Crypter k = new Crypter();// = new a(“Ciao”);
try (BufferedReader input = new BufferedReader(new InputStreamReader(System.in))) {
k.setWord(input.readLine());
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(“Crypted: ” + k.getCryptedString());
System.out.println(“Decrypted: ” + k.decryptString(k.getCryptedString()));
System.out.println(“Static Decrypted: ” + Crypter.decryptString(“fldr”));
}
}
[:]