Voici des exemples de programmes en **C**, **C++**, et **Java** pour implémenter le
chiffre de **Atbash**.
### 1. Programme en C :
```c
#include <stdio.h>
#include <string.h>
void atbashCipher(char *text) {
for(int i = 0; text[i] != '\0'; i++) {
if(text[i] >= 'A' && text[i] <= 'Z') {
text[i] = 'Z' - (text[i] - 'A');
}
else if(text[i] >= 'a' && text[i] <= 'z') {
text[i] = 'z' - (text[i] - 'a');
}
}
}
int main() {
char text[100];
printf("Entrez un texte à chiffrer : ");
fgets(text, 100, stdin);
// Enlever le saut de ligne à la fin de la chaîne
text[strcspn(text, "\n")] = '\0';
atbashCipher(text);
printf("Texte chiffré : %s\n", text);
return 0;
}
```
### 2. Programme en C++ :
```cpp
#include <iostream>
#include <string>
using namespace std;
void atbashCipher(string &text) {
for (int i = 0; i < [Link](); i++) {
if (text[i] >= 'A' && text[i] <= 'Z') {
text[i] = 'Z' - (text[i] - 'A');
}
else if (text[i] >= 'a' && text[i] <= 'z') {
text[i] = 'z' - (text[i] - 'a');
}
}
}
int main() {
string text;
cout << "Entrez un texte à chiffrer : ";
getline(cin, text);
atbashCipher(text);
cout << "Texte chiffré : " << text << endl;
return 0;
}
```
### 3. Programme en Java :
```java
import [Link];
public class AtbashCipher {
public static String atbashCipher(String text) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < [Link](); i++) {
char c = [Link](i);
if (c >= 'A' && c <= 'Z') {
[Link]((char) ('Z' - (c - 'A')));
} else if (c >= 'a' && c <= 'z') {
[Link]((char) ('z' - (c - 'a')));
} else {
[Link](c); // Ajouter le caractère tel quel s'il n'est pas
une lettre
}
}
return [Link]();
}
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Entrez un texte à chiffrer : ");
String text = [Link]();
String encryptedText = atbashCipher(text);
[Link]("Texte chiffré : " + encryptedText);
}
}
```
### Explication du code :
1. **Fonction `atbashCipher`** : Elle prend une chaîne de caractères et applique le
chiffre de **Atbash** sur chaque lettre. Si le caractère est une lettre majuscule,
il est remplacé par sa lettre opposée dans l'alphabet (A ↔ Z, B ↔ Y, etc.). Si
c'est une lettre minuscule, le même principe s'applique mais avec les minuscules (a
↔ z, b ↔ y, etc.).
2. **Caractères non alphabétiques** : Les caractères qui ne sont pas des lettres
(comme les espaces ou les signes de ponctuation) sont laissés inchangés dans tous
les programmes.
### Test de fonctionnement :
- Entrée : **"HELLO"**
- Sortie : **"SVOOL"**
Ces programmes peuvent être adaptés et étendus en fonction des besoins (par
exemple, pour gérer des textes plus longs ou pour ajouter des fonctionnalités
supplémentaires).