Problem encryption program in c++

Status
Not open for further replies.

Shikher_neo

Broken In
hi buddy,

I have built an encryption program using c++ which works fine with text files.but it does not work et al with any other format(like jpg or exe).i have tried opening files as binary and used read and write functions but to no avail.
Please help me.
 

redhat

Mad and Furious
I didnt get it...
what sort of an ebcryption program have you made??
encrypting exe's picture files and text all require different methods....
can u please explain the algorith here??
 

QwertyManiac

Commander in Chief
Yes text and image encryption techniques if to be done efficiently need to be done in separate methods using the ones best suited to each.

However, a simple hack to your problem would be to read the binary files (JPG, et. all) byte-by-byte (ie) 8-bits at a time. This would give you values lesser than 256 just like your text encryption probably needs.
 
Last edited:

legolas

Padawan
how would you read in an exe file, in binary mode? the format of the output file can be anything?
On the decryption part, you just do the opposite and write it as .exe extension is it?
 

dheeraj_kumar

Legen-wait for it-dary!
Opening files in text mode doesnt consider the whitespace characters. But since they are important in binary files, open them in binary mode.
 
OP
Shikher_neo

Shikher_neo

Broken In
well i have written the method to read byte by byte.That is ensured by by read and write functions themselves.
The problem is when i input from exe s (or image file) and perform some calculations based on the ASCII code of the key , it does not work; the output file is empty.While the same method works fine with text.
Do I need to do something different for manipulating these files?
please help
 

dheeraj_kumar

Legen-wait for it-dary!
Ah wait.... I think I understand. First, you need to change your algorithm. Why? your algorithm calculates the new ascii code for a given ascii code. But you should consider that ascii characters are not all text and characters, but also include control codes. Check them out at www.asciitable.com

If the algorithm convers a certain value to the End of File value, and it is written to the file, then when the file is opened again, only characters till the end of file is read, which is not till the real end of file, but the EOF value written by the algorithm.

So change your algo to avoid those control chars and you should be okay. I had a similar problem with my class 12 projects, then found this after looking at the file with Hex Workshop :)
 

redhat

Mad and Furious
try doing this...
Open an image or exe file in notepad
without any changes only click on Save As and save it with the same extension as the original file...
Does it work?? NO!!!
why?, because EXE's need to be compiled.. they wont execute if you save a binary file with extension.exe
 

dheeraj_kumar

Legen-wait for it-dary!
^^ WRONG.

I agree it may not work. But when a code has already been compiled into an EXE, it doesnt need to be compiled whenever there is a modification.

It doesnt work when you open/save it in notepad, because of the reason I gave above. TEXT editors deal whitespace characters in a DIFFERENT way. EXE is PURE BINARY. Text is TRANSLATED to a display-able form on screen. EXE files CANNOT cope with the translation.

And image files wont work with extension exe because the file format is simply different. EXE files need to be a PE format with MZ in order to work. EXE file format is extremely interesting, and you might want to google more than that :)

edit: I use caps to emphasize a point. sorry if anyone thought i was shouting.
 
Last edited:

ilugd

Beware of the innocent
shiker_neo: when you run the encryption routine on the binary file, you get an encrypted file? can you check if the size of the file is 0kb or some reasonable size?
 
Status
Not open for further replies.
Top Bottom