Correction Cesar

This commit is contained in:
Meutel 2019-06-01 18:23:06 +02:00
parent 81316c066c
commit 53e82c7673
2 changed files with 20 additions and 2 deletions

View File

@ -13,7 +13,16 @@ public class CesarChiffre {
// int position(char c): retourne la position de la lettre dans l'alphabet
// (à partir de 0)
return in;
char[] out = new char[in.length];
for (int i = 0; i<in.length; i++) {
char c = in[i];
if (c == ' ') {
out[i] = c;
} else {
out[i] = ALPHABET[(position(c)+cle) % ALPHABET.length];
}
}
return out;
}
}

View File

@ -13,7 +13,16 @@ public class CesarDechiffre {
// int position(char c): retourne la position de la lettre dans l'alphabet
// (à partir de 0)
return in;
char[] out = new char[in.length];
for (int i = 0; i<in.length; i++) {
char c = in[i];
if (c == ' ') {
out[i] = c;
} else {
out[i] = ALPHABET[(ALPHABET.length+position(c)-cle) % ALPHABET.length];
}
}
return out;
}
}