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