[NO-PARSE]#include <iostream>
#include <cstring>
#include <algorithm>
// Vigenere Cipher Methods:
// Note: assumes that both strings as arguments have length > 0, and that
// the key only contains letters of the alphabet from [A-Z]
void vigenere_encrypt(std::string& s, std::string key)
{
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
std::transform(key.begin(), key.end(), key.begin(), ::toupper);
int j = 0;
for (int i = 0; i < s.length(); i++)
{
if (isalpha(s))
{
s += key[j] - 'A';
if (s > 'Z') s += -'Z' + 'A' - 1;
}
j = j + 1 == key.length() ? 0 : j + 1;
}
}
void vigenere_decrypt(std::string& s, std::string key)
{
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
std::transform(key.begin(), key.end(), key.begin(), ::toupper);
int j = 0;
for (int i = 0; i < s.length(); i++)
{
if (isalpha(s))
{
s = s >= key[j] ?
s - key[j] + 'A' :
'A' + ('Z' - key[j] + s - 'A') + 1;
}
j = j + 1 == key.length() ? 0 : j + 1;
}
}
int main(void)
{
std::string s("AceInfinity's Example");
std::string key("Passkey");
vigenere_encrypt(s, key);
std::cout << "Encrypted: " << s << std::endl;
vigenere_decrypt(s, key);
std::cout << "Decrypted: " << s << std::endl;
return 0;
}[/NO-PARSE]