•
•
•
•
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
![]() |
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.
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.
"I'm not dumb. I just have a command of thoroughly useless information."
- Calvin, of Calvin and Hobbes
- Calvin, of Calvin and Hobbes
•
•
Join Date: Jul 2008
Posts: 294
Reputation:
Rep Power: 2
Solved Threads: 43
I see a monstrous fragment in attached code:
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.
cpp Syntax (Toggle Plain Text)
string FileName; char __TEMP__[256]; cin.getline(__TEMP__, 256); FileName = __TEMP__; delete [] __TEMP__;
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,809
Reputation:
Rep Power: 11
Solved Threads: 184
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
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.
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Hidden program installs .dlls with randomly generated names in random "notify" reg. (Viruses, Spyware and other Nasties)
- Internet graphics display problem (OS X)
- xp gif weirdness, trying to track the cause (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: c++ please help
- Next Thread: Question about accounting program



Linear Mode