Hi,
I’m trying to XOR / OR to easily encrypt my
configurations. I’m having a simple problem, the algorithm is not
working:
[code]
Using
namespace std;
string XorUtility::XorStream(string Pass, string Text)
{
string
Ciph;
Ciph.clear();
char code;
code
= (char)0;
for (string::iterator i =
Pass.begin(); i != Pass.end(); i++)
{
code
^= *i;
}
for (string::iterator i =
Text.begin(); i != Text.end(); i++)
{
code
^= *i;
Ciph.push_back(code);
}
return Ciph;
}
string
XorUtility::OrStream(string Pass, string Text)
{
string
Ciph;
Ciph.clear();
char code;
code
= (char)0;
char letter;
for (string::iterator i =
Pass.begin(); i != Pass.end(); i++)
{
code
^= *i;
}
for (string::iterator i =
Text.begin(); i != Text.end(); i++)
{
letter
= code | *i;
Ciph.push_back(letter);
code
^= letter;
}
return Ciph;
}
[/code]
The test I use is:
[code]
s
= "Teste do Xor do
Dirso";
s2 = XorUtility::getInstance()->XorStream("OK", s);
s3
= XorUtility::getInstance()->OrStream("OK", s2);
[/code]
The output I’m getting for “s3” is:
s3 = "Tugrww3|
o{9}v2V}~{"
What did I do wrong?
Thanks,
Dirso.