40 lines
715 B
C++
40 lines
715 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 08/03/2025
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cctype>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
void decryptCaesarCipher(char *str);
|
|
|
|
int main(void) {
|
|
char str[SIZE]; //DEFGHIJKLMNOPQRSTUVWXYZABC
|
|
|
|
cout << "Inserisci una frase: ";
|
|
cin.getline(str, SIZE);
|
|
|
|
decryptCaesarCipher(str);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void decryptCaesarCipher(char *str) {
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (isalpha(str[i])) {
|
|
if (isupper(str[i])) {
|
|
str[i] = ((str[i] - 'A' + 23) % 26) + 'A';
|
|
} else if (islower(str[i])) {
|
|
str[i] = ((str[i] - 'a' + 23) % 26) + 'a';
|
|
}
|
|
}
|
|
}
|
|
|
|
cout << "Frase decodificata: " << str << endl;
|
|
} |