When scrambling is to be done, your program is to read in the initial input file (using the read command) and write it out to the output file (using the write command). Your program will then make the designated number of passes through the output file to scramble it. On the first pass your program is to start with the first character and swap it with the second character, then take the third character and swap it with the fourth, until the end of the file. On the second pass your program is to start with the first character and swap it with the fourth character, then take the 5th character and swap it with the 8th, and so on until the end of the file. On a third pass your program is to start with the first character and swap it with the 6th character and so on. If there are extra characters at the end of the file that cannot be swapped, then they are printed as they are. The reverse is done for unscrambling.
For example consider the following line of text:
There is no place like home.
After the first pass the line should look like the following:
hTre esin olpca eilekh mo.e
After a second pass the line should look like the following:
eTrhies o napcllei kheeo.m
Consider another example, if the file in.file contained the following text:
Row row row your boat gently down the stream. Merrily merrily merrily merrily life is but a dream.And the following command was issued: a.out S 4 in.file out.file
The file out.file would contain the following text:
oR owworor yrwau bgteodnytol nhwrettms eM.ea rlrmiry rleryeilm rmyei rlrliey fiitsu br edaa.mIf the following command were to now be issued: a.out U 4 out.file out2.file
The file out2.file would contain the following text:
Row row row your boat gently down the stream. Merrily merrily merrily merrily life is but a dream.
Remember that spaces and carriage returns are characters also.