User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,584 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,650 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 162 | Replies: 4 | Solved
Reply
Join Date: Dec 2007
Posts: 112
Reputation: TheBeast32 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
TheBeast32's Avatar
TheBeast32 TheBeast32 is online now Online
Junior Poster

Weird Compression

  #1  
33 Days Ago
Hi, I have been making a program that encrypts files. It works, but it compresses them. It only does it a little bit, but it does. It's weird. Why is it doing this?
I have attached a zipped folder with the code, binary, an encrypted file, and the original file. The key to decrypt the file is "hello" without quotes. Once you decrypt the included file, you'll see that they are now the same size.
Attached Files
File Type: zip Encryptor.zip (132.1 KB, 5 views)
"I'm not dumb. I just have a command of thoroughly useless information."
- Calvin, of Calvin and Hobbes
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Posts: 294
Reputation: ArkM has a spectacular aura about ArkM has a spectacular aura about 
Rep Power: 2
Solved Threads: 43
ArkM ArkM is offline Offline
Posting Whiz in Training

Re: Weird Compression

  #2  
33 Days Ago
I see a monstrous fragment in attached code:
  1. string FileName;
  2.  
  3. char __TEMP__[256];
  4. cin.getline(__TEMP__, 256);
  5.  
  6. FileName = __TEMP__;
  7. delete [] __TEMP__;
Don't continue. You try to deallocate (free) stack (automatic) array. Of course, now program stack is corrupted, program behaviour is undefined and so on...

Apropos, see quote from C++ Standard:
17.4.3.1.2 Global names
Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

So it's not recommended to assign __TEMP__ to your local variables: it's not a good practice.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,809
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 184
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Weird Compression

  #3  
33 Days Ago
You have discounted newline conversions.

On Windows, the newline character represents the ASCII sequence CR LF.
When your program reads it, it gets '\n'. The newline is encrypted thus and so the output file is shorter than the input file, because the encrypted data doesn't have as many '\n's (if any) as the source.

You'll also notice that when it says File Length: that it gives the shorter size.

When decrypting, you get back that '\n', which is written to file as CR LF, thus increasing the output file size (back to the original size).


Some observations:
<conio.h> is evil.
Use functions.


Hope this helps.
Reply With Quote  
Join Date: Dec 2007
Posts: 112
Reputation: TheBeast32 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
TheBeast32's Avatar
TheBeast32 TheBeast32 is online now Online
Junior Poster

Re: Weird Compression

  #4  
31 Days Ago
Thanks. I thought it was that, but I wasn't sure. Also, I like <conio.h>.
"I'm not dumb. I just have a command of thoroughly useless information."
- Calvin, of Calvin and Hobbes
Reply With Quote  
Join Date: Feb 2008
Posts: 63
Reputation: aminit is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
aminit's Avatar
aminit aminit is offline Offline
Junior Poster in Training

Re: Weird Compression

  #5  
31 Days Ago
Hello :

Nice job, which algorithm you used to do this??

thanks
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:59 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC