School-Coding-Cpp/sfusi/encrypt_atbashCipher.cpp

46 lines
764 B
C++

/*
Nome: Mario
Cognome: Montanari
Classe: 3AIN
Data: 08/03/2025
*/
#include <iostream>
#include <cctype>
#define SIZE 100+1
using namespace std;
void encryptAtbashCipher(char *str);
int main(void) {
char str[SIZE]; //ABCDEFGHIJKLMNOPQRSTUVWXYZ
cout << "Inserisci una frase: ";
cin.getline(str, SIZE);
encryptAtbashCipher(str);
return 0;
}
void encryptAtbashCipher(char *str) {
int j = 0;
for (int i = 0; str[i] != '\0'; i++) {
if (!isalpha(str[i])) {
str[j++] = str[i];
} else {
if (isupper(str[i])) {
str[j++] = 'Z' - (str[i] - 'A');
} else if (islower(str[i])) {
str[j++] = 'z' - (str[i] - 'a');
}
}
}
str[j] = '\0';
cout << "Frase codificata: " << str << endl;
}