It's been a long time since I've touched C++ and I've never been quite fluent in the language, so forgive my ignorance.
I've written the following little program to mess around with XOR encryption:
#include <iostream>
#include <iomanip>
#include "string.h"
using std::cout;
using std::endl;
using std::hex;
using std::string;
string cipher(string msg, char key);
int main(void)
{
string msg = "Now is the winter of our discontent, made glorious summer by this sun of York.";
char key = 's'; // ASCII 115
string ctext = cipher(msg, key);
cout << "Plaintext: " << msg << endl;
cout << "Ciphertext (hex): ";
for (int i = 0; i < ctext.size(); i++)
cout << hex << ctext[i];
return 0;
}
string cipher(string msg, char key)
/*
Symmetric XOR cipher
*/
{
for(int i = 0; i < msg.size(); i++)
msg[i] ^= key;
return msg;
}
This code outputs the following:
Plaintext: Now is the winter of our discontent, made glorious summer by this sun of York.
Ciphertext (hex): =SSSSSS_SSSS
SSSS*]
Why can I not get the hex values to output? What am I doing wrong?
Also, any general advice is appreciated.