1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| import java.util.Scanner;
public class Crypto {
static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
static final int DECALAGE = 4;
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Veuillez entrer une chaine de caracteres : ");
String s = scanner.nextLine();
// la chaine a coder
String aCoder = "";
// la chaine codee
String chaineCodee = "";
/*******************************************
* Completez le programme a partir d'ici.
*******************************************/
aCoder = s;
int l = aCoder.length();
for(int i=0; i<l; ++i){
int num1 = Character.getNumericValue(ALPHABET.charAt(i));
int num2 = Character.getNumericValue(aCoder.charAt(i));
if(num1 == num2){
num1 = num2 + DECALAGE;
}
chaineCodee += num1;
// Ensuite, reconvertir des int en char ?? Possible ??
}
/*******************************************
* Ne rien modifier apres cette ligne.
*******************************************/
System.out.format("La chaine initiale etait : '%s'\n", s);
if (aCoder.isEmpty()) {
System.out.println("La chaine a coder est vide.\n");
} else {
System.out.format("La chaine a coder est : '%s'\n", aCoder);
System.out.format("La chaine codee est : '%s'\n", chaineCodee);
}
}
} |