#include <iostream>
#include <string>
// Function to encrypt or decrypt a string using XOR
std::string xorCipher(const std::string& input, char key) {
std::string output = input;
for (size_t i = 0; i < input.size(); i++) {
output[i] ^= key; // XOR each character with the key
}
return output;
}
int main() {
std::string text = "May the Force be with you.";
char key = 'K'; // Encryption/Decryption key
// Encrypt the string
std::string encrypted = xorCipher(text, key);
std::cout << "Encrypted: \n" << encrypted << std::endl;
// Decrypt the string (using the same function)
std::string decrypted = xorCipher(encrypted, key);
std::cout << "Decrypted: \n" << decrypted << std::endl;
}
/*
run:
Encrypted:
$9(.k).k<"?#k2$>e
Decrypted:
May the Force be with you.
*/