Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 15-05-2008, 05:45 PM   #1 (permalink)
Right Off the Assembly Line
 
Shikher_neo's Avatar
 
Join Date: Oct 2006
Posts: 47
Default Problem encryption program in c++


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.
__________________
God Does Not Play Dice
-Albert Einstein
Shikher_neo is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 15-05-2008, 06:05 PM   #2 (permalink)
Mad and Furious
 
redhat's Avatar
 
Join Date: May 2006
Location: Visual Basic 6.0
Posts: 453
Default Re: Problem encryption program in c++

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??
__________________
My new Tech Blog : http://technewspaper.blogspot.com/
redhat is offline  
Old 15-05-2008, 09:40 PM   #3 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Problem encryption program in c++

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.
__________________
Harsh J
www.harshj.com

Last edited by QwertyManiac; 15-05-2008 at 10:49 PM. Reason: Sorta confused with the *tions.
QwertyManiac is offline  
Old 16-05-2008, 02:35 PM   #4 (permalink)
Alpha Geek
 
Join Date: Feb 2005
Posts: 959
Default Re: Problem encryption program in c++

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?
__________________
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
legolas is offline  
Old 16-05-2008, 05:28 PM   #5 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Problem encryption program in c++

Yes, its another file in the end after all?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 17-05-2008, 08:45 AM   #6 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: Problem encryption program in c++

Opening files in text mode doesnt consider the whitespace characters. But since they are important in binary files, open them in binary mode.
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file
dheeraj_kumar is offline  
Old 17-05-2008, 03:27 PM   #7 (permalink)
Right Off the Assembly Line
 
Shikher_neo's Avatar
 
Join Date: Oct 2006
Posts: 47
Default Re: Problem encryption program in c++

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
__________________
God Does Not Play Dice
-Albert Einstein
Shikher_neo is offline  
Old 17-05-2008, 05:17 PM   #8 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Problem encryption program in c++

You are sure you are opening it in binary mode?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 18-05-2008, 07:59 AM   #9 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: Problem encryption program in c++

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
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file
dheeraj_kumar is offline  
Old 18-05-2008, 10:49 PM   #10 (permalink)
Mad and Furious
 
redhat's Avatar
 
Join Date: May 2006
Location: Visual Basic 6.0
Posts: 453
Default Re: Problem encryption program in c++

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
__________________
My new Tech Blog : http://technewspaper.blogspot.com/
redhat is offline  
Old 19-05-2008, 07:51 AM   #11 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: Problem encryption program in c++

^^ 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.
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file

Last edited by dheeraj_kumar; 19-05-2008 at 07:58 AM.
dheeraj_kumar is offline  
Old 21-05-2008, 02:14 PM   #12 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: Problem encryption program in c++

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?
__________________
Life is too short. Have fun.
ilugd is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
java smiley program problem ratedrsuperstar Programming 1 14-05-2008 09:53 AM
Need Freeware Encryption program ramprasad QnA (read only) 1 15-06-2007 12:27 PM
END PROGRAM PROBLEM kumarn_2004 QnA (read only) 2 11-12-2005 04:54 PM
new program in 'close program menu' list and more....... vishakadatta QnA (read only) 2 12-04-2005 11:33 PM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:00 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2