61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 08/03/2025
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cctype>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
void decryptCarbonarCipher(char *str, const char *carbonarAlphabet);
|
|
|
|
int main(void) {
|
|
const char carbonarAlphabet[] = "OPGTIVCHE RNMABQLZDUF S";
|
|
char str[SIZE]; //ABCDEFGHI LMNOPQRSTUV Z
|
|
|
|
cout << "Inserisci una frase: ";
|
|
cin.getline(str, SIZE);
|
|
|
|
decryptCarbonarCipher(str, carbonarAlphabet);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void decryptCarbonarCipher(char *str, const char *carbonarAlphabet) {
|
|
char carbonarStr[SIZE];
|
|
int j = 0;
|
|
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (
|
|
str[i] == 'J' || str[i] == 'j' ||
|
|
str[i] == 'K' || str[i] == 'k' ||
|
|
str[i] == 'W' || str[i] == 'w' ||
|
|
str[i] == 'X' || str[i] == 'x' ||
|
|
str[i] == 'Y' || str[i] == 'y'
|
|
) {
|
|
cout << "Frase non valida!" << endl;
|
|
return;
|
|
}
|
|
|
|
if (!isalpha(str[i])) {
|
|
carbonarStr[j++] = str[i];
|
|
} else {
|
|
if (isupper(str[i])) {
|
|
int r = str[i] - 'A';
|
|
carbonarStr[j++] = toupper(carbonarAlphabet[r]);
|
|
} else if (islower(str[i])) {
|
|
int r = str[i] - 'a';
|
|
carbonarStr[j++] = tolower(carbonarAlphabet[r]);
|
|
}
|
|
}
|
|
}
|
|
|
|
carbonarStr[j] = '\0';
|
|
|
|
cout << "Frase decodificata: " << carbonarStr << endl;;
|
|
} |