Challenge 9 – Compress and decompress an ASCII file in C++

Difficulty ![]() |
![]() |
This Challenge was proposed for the now defunct C/C++ programming list CWORLD in 1999.
The source code of the challenge has been updated to modern C++, but maintaining the essence of the challenge, which its original author wanted to transmit.
Date: 06-XI-2000
Created by: RiMS
Challenge winner: José Luis De la Cruz Lázaro
This challenge is going to sound a bit strange but what I’m asking is quite simple: it involves encrypting or compressing a common, wild ASCII text file (with DOS or UNIX line breaks) and performing the reverse process using the following method:
Since there are 127 ASCII characters (or 128 depending on who explains it), they are encoded in 8 bits, always having bit 7 at 0. Therefore, to take advantage of that bit, shifts will be made every eight BYTES so that they occupy seven Bytes. If it happens that the text has a number of characters that is not divisible by 8, the other bits of the BYTE are simply filled with 0 and the process is finished.
The way the program is coded would be completely free and I can only give you a suggestion of how I would like it to work:
From the prompt write RETO0009 flag InputFile OutputFile
for example:
RETO0009 C Test.txt Output.enc (to compress the file test.txt and generate the file output.enc)
RETO0009 D Output.enc Test.txt (to decompress the file output.enc)
Well, let’s see if you understand what I’m asking with an example:
“RETO0009 JE” is an ASCII text of 11 characters (without the quotes, obviously).
At bit level it would be coded as follows:
*Note: To view this code correctly on mobile devices, place the mobile phone in horizontal position.
R E T O 0 0
82 69 84 79 48 48
0101.0010 0100.0101 0101.0100 0101.1111 0011.0000 0011.0000
* * * * * *
0 9 space J E
48 57 32 74 69
0011.0000 0011.1001 0010.0000 0100.1010 0100.0101
* * * * *
By removing each 0 marked with * it should look like this:
1010.0101 0001.0110 1010.0101 1111.0110 0000.1100
^ ^ ^ ^ ^ ^
R E T O 0 0
0001.1000 0011.1001 0100.0001 0010.1010 0010.1000
^ ^ ^ ^ ^ ^^^
0 9 space J E (padding 0 to complete BYTE)
I hope that it is clear and that it is not too confusing for a lot of people to get hooked… oh I forgot, by the way, it compresses, check that the file is pure ASCII. Otherwise, cancel.
I am studying the ICE grading method to see if I understand but I ask please if someone who is not participating helps me grade the answers because above all it seems to me that it will be difficult for me to connect to the internet during the week…
AND FINALLY I CAN ONLY SAY …. BEST OF LUCK AND MAY THE BEST CODE WIN….
If you liked this challenge remember to leave a comment in our guestbook