metalzera
Messages postés5Date d'inscriptiondimanche 29 mars 2015StatutMembreDernière intervention28 août 2016
-
17 mai 2015 à 16:03
Bonjours voila je debute en java et en cherchant un peu partout des programmes à essayer je suis tombé sur le programme de decryptage VigenereCipher que voici
public class VigenereCipher {
public static void main(String[] args) {
String key = "VIGENERECIPHER";
String ori = "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!";
String enc = encrypt(ori, key);
System.out.println(enc);
System.out.println(decrypt(enc, key));
}
static String encrypt(String text, final String key) {
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c < 'A' || c > 'Z') continue;
res += (char)((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
j = ++j % key.length();
}
return res;
}
static String decrypt(String text, final String key) {
String res = "";
text = text.toUpperCase();
for (int i = 0, j = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c < 'A' || c > 'Z') continue;
res += (char)((c - key.charAt(j) + 26) % 26 + 'A');
j = ++j % key.length();
}
return res;
}
}
ma question est: est-il possible de le modifier afin qu"il remplisse uniquement la fonction décrypter? si oui comment ? je ne demande pas à ce qu'on me mache le boulot je veux juste savoir si c'est possible et que l'on me donne un point de depart
merci beacoup ^^