XOREncryption/main.cpp
2013-10-05 18:19:47 -04:00

32 lines
685 B
C++

//
// main.cpp
//
// Created by Kyle Banks on 2013-10-05.
//
#include <iostream>
using namespace std;
string encryptDecrypt(string toEncrypt) {
char key[3] = {'K', 'C', 'Q'}; //Any chars will work, in an array of any size
string output = toEncrypt;
for (int i = 0; i < toEncrypt.size(); i++)
output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))];
return output;
}
int main(int argc, const char * argv[])
{
string encrypted = encryptDecrypt("kylewbanks.com");
cout << "Encrypted:" << encrypted << "\n";
string decrypted = encryptDecrypt(encrypted);
cout << "Decrypted:" << decrypted << "\n";
return 0;
}