#include<iostream>
#include<string>
using namespace std;
string encrypt(string m, string key){
string ciphertext = "";
for(int i = 0;i < m.size();i++){
ciphertext += ((m[i] - 'A') + (key[i % key.size()] - 'A')) % 26;
ciphertext[i] = ciphertext[i] + 'A';
}
return ciphertext;
}
string decrypt(string m, string key){
string plaintext = "";
for(int i = 0;i < m.size();i++){
plaintext += ((m[i] - 'A') - (key[i % key.size()] - 'A')) % 26;
if(plaintext[i] < 0) plaintext[i] += 26;
plaintext[i] = plaintext[i] + 'A';
}
return plaintext;
}
int main(){
string Key = "SET";
string message = "TOPSECRET";
string cipher = encrypt(message, Key);
cout << cipher << endl;
string plaintext = decrypt(cipher, Key);
cout << plaintext << endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgZW5jcnlwdChzdHJpbmcgbSwgc3RyaW5nIGtleSl7CglzdHJpbmcgY2lwaGVydGV4dCA9ICIiOwoJZm9yKGludCBpID0gMDtpIDwgbS5zaXplKCk7aSsrKXsKCQljaXBoZXJ0ZXh0ICs9ICgobVtpXSAtICdBJykgKyAoa2V5W2kgJSBrZXkuc2l6ZSgpXSAtICdBJykpICUgMjY7CgkJY2lwaGVydGV4dFtpXSA9IGNpcGhlcnRleHRbaV0gKyAnQSc7Cgl9CglyZXR1cm4gY2lwaGVydGV4dDsKfQoKc3RyaW5nIGRlY3J5cHQoc3RyaW5nIG0sIHN0cmluZyBrZXkpewoJc3RyaW5nIHBsYWludGV4dCA9ICIiOwoJZm9yKGludCBpID0gMDtpIDwgbS5zaXplKCk7aSsrKXsKCQlwbGFpbnRleHQgKz0gKChtW2ldIC0gJ0EnKSAtIChrZXlbaSAlIGtleS5zaXplKCldIC0gJ0EnKSkgJSAyNjsKCQlpZihwbGFpbnRleHRbaV0gPCAwKSBwbGFpbnRleHRbaV0gKz0gMjY7CgkJcGxhaW50ZXh0W2ldID0gcGxhaW50ZXh0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