The problem is that the encrypted string can contain embedded 0 characters, which in C strings mean the end of the string. Anything up to the first 0 is printed.
So yes, you might need a loop.
Or an algorithm that does the loop for you:
Code:
#include <algorithm>
#include <iterator>
...
copy(o, o + strlen(input), ostream_iterator<char>(cout, ""));
But then in C++ land there is also a string object which, among other benefits, should get output entirely regardless of the embedded 0's (they are non-printing, though, so you might see a space instead).
Code:
#include<iostream>
#include<string>
using namespace std;
string XorStr( string input, const string& key)
{
for( unsigned int i = 0, k = 0; i < input.size(); i++ )
{
input[i] = input[i] ^ key[k];
++k;
if (k >= key.size()) k = 0;
}
return input;
}
int main()
{
//int input[MAX] = {0x14, 0x6, 0x9, 0x1b, 0x6, 0x6f, 0x1c}, if 1st arg is int name[MAX]
string input("giorgus");
string key("giorgos");
cout << "Decrypted string is: ";
cout << XorStr(input, key);
cout << endl;
system("pause");
return 0;
}