#include <iostream>
#include <string>
#include<algorithm>
#include<cctype>
using namespace std;
class Vigenere
{
public:
string key;
Vigenere(string key)
{
for(auto &i:key)
{
if(i >= 'A' && i <= 'Z')
this->key += i;
else if(i >= 'a' && i <= 'z')
this->key += i;
}
}
string encrypt(string text)
{
string out;
int j=0;
for(auto &i:text)
{
if(i==' '){
out+=' ';
continue;
};
if(isupper(i))
out += (i + key[j] - 2*'A') % 26 + 'A';
else
out += (i + key[j] - 2*'A') % 26 + 'a';
j = (j + 1) % key.length();
}
return out;
}
string decrypt(string text)
{
string out;
int j=0;
for(auto &i:text)
{
if(i==' '){
out+=' ';
continue;
};
if(isupper(i))
out += (i - key[j] + 26) % 26 + 'A';
else
out += (i - key[j] + 26) % 26 + 'a';
j = (j + 1) % key.length();
}
return out;
}
};
using namespace std;
int main()
{
Vigenere cipher("LEMON");
string original= "ATTA cka";//Должно вывести -> LXFO pve
// getline(cin,original);
string encrypted = cipher.encrypt(original);
string decrypted = cipher.decrypt(encrypted);
cout <<"Text : "<< original << endl;
cout << "Key: " << cipher.key << endl;
cout << "Cipher: " << encrypted << endl;
cout << "Decipher: " << decrypted << endl;
}
if(isupper(i))
out += (i + key[j] - 2*'A') % 26 + 'A';
else
out += (i + key[j] - 2*'A') % 26 + 'a';
out += ((i - 'A') + (key[j] - 'A')) % 26 + 'A';
out += ((i - 'a') + (key[j] - 'A')) % 26 + 'a';