473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Bypassing the EOF marker

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.
Jun 27 '08 #1
2 1798
philmasterplus wrote:
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.
The way you handle it, it isn't really a text file, is it? Recognizing
EOF markers inside the file, or not, is totally system dependent.
There is no general rule for this.

Your best shot will probably be to open the files in binary mode,
like:

ifstream ifs("test.txt", std::ios::binary);
Bo Persson
Jun 27 '08 #2
On 19 avr, 14:23, philmasterplus <philmasterp...@gmail.comwrote:
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.
More to the point, the "obfuscated" file isn't text, so cannot
be written (nor read) if the file is opened in text mode. You
have two choices: open in binary, or use something like rot-13
for obfuscation, which ensures that the obfuscated data is text.
(Rot-13 is very minimal obfuscation, but throw in a little
shuffling, and it should be as good or better than xor'ing.)
The code can be simplified as follows:

<code>
//Assuming all necessary includes are in place
int main()
{
ifstream ifs("test.txt");
If this is to read your obfuscated text:

std::ifstream ifs( "test.txt", std::ios::binary ) ;

And of course, in real code, you'll want to check that the open
succeeded.
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
In theory, this test may cause you to miss the last character.
There are two "classical" solutions:

while ( ifs.get( cbuf ) ) { ...

or declare cbuf as an int, and:

while ( cbuf != EOF ) { ...

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Trautmann | last post by:
Hi all, is there any standard for grip markers? I've found the fo:marker, but I look for some kind of support for "grip marker" or "side makers" - what's the correct English / XSL term to look...
25
by: Haines Brown | last post by:
I have a table with three columns, and I want the data in the first column to align left, while that in the remaining columns to align right: #testTable { text-align: right; } #leftcol {...
3
by: KNE | last post by:
I'm writing some code that is formating an output file being generated within a web app. I want to allow the site administrator to configure the characters that will mark the end of each...
1
by: Wannabe_Geek | last post by:
Do we have something in ASP.net like freemarker for java.(freemarker.sourceforge.net) The idea is to use simple HTML file as template for the site and replace the Marker tags with appropriate...
1
by: Uri Dimant | last post by:
Hi,friends I meant Flag on text editor. It allows you to move from flag to flag only within one class/module. If you put another flag within different module/class in the same project then it...
0
by: geniet | last post by:
Hello all of you, I am looking for a program where I can add and edit the APP3 marker according to jps format (if needed Python/PIL can be used). The setup of the APP3 marker comes from this...
1
by: =?Utf-8?B?QXVzdGluIFN0ZXBoZW5z?= | last post by:
In my commercial financial application I run a deposit report. I use an option to copy the report to the Clipboard. I then run a .NET consol app to “grab†the Clipboard and format the data...
4
by: TS | last post by:
Steven, i lost this message conversation from outlook express and made a post online (see last one on this page). Please answer it as it hasn't been yet. thanks The clientID of our controls...
2
by: flymo | last post by:
Hello All, Hopefully this is the correct forum... I have some code that creates a text (dat) for a billing process created in Access2000, I add an Eof of Line marker to each line item and then...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.