I am trying to create a simple file encoder (obfuscator) class using
the XOR(^) operator.
I am using objects of the class ifstream and ofstream to input/output
to the file. Right now, I am experimenting with xor-encoding a file
with a given C-string.
The problem is, the obfuscated file contains the EOF character for my
system, and my program cannot proceed to reencode (decode) the rest of
the obfuscated file.
The code can be simplified as follows:
<code>
//Assuming all necessary includes are in place
int main()
{
ifstream ifs("test.txt");
char cbuf;
string sbuf;
//Other code blah blah blah...
cbuf = ifs.get();
while (!ifs.eof()) //Recognizes the EOF-marker-in-the-middle-of-the-
file
{
sbuf.push_back(cbuf);
cbuf = ifs.get();
}
//Other code blah blah blah...
}
</code>
Yeah, I know, loading the whole file into a std::string variable is a
BAD idea, but it's a temporary hack. Which brings me to another
question: How do you xor-encode a file without opening an ifstream and
an ofstream? I know about the std::fstream class, but I don't know how
to use it.
Any form of example code (preferably with indents) would be
appreciated!
P. S. please also comment on my programming style. On a request, I
will upload the whole project.