CSC 271

Homework 3
assigned 29 Oct, due 14 Nov

Write a C program named "scramble" for sending and receiving secret messages using a multiplication cipher. For every line it reads from stdin, it arranges the characters into a two-dimensional array of N columns and as many rows as it takes (fill with spaces to a multiple of N), filling each row from left to right, and then outputs the same characters in a different order by going down the leftmost column, then the second leftmost, and so on.

N defaults to 10, but should be settable with a command-line option "-cols N".

If command-line arguments are provided, the program should treat them as files to be read instead of using stdin.

The command-line option "-u" tells the program to unscramble instead. Also, if the program is invoked with the name "unscramble" rather than "scramble", it should behave as though it had been given the "-u" option.

The "-u" and "-cols N" options may be given in either order, but will be separate words on the command line (i.e. you don't have to handle "-ucols 6"), and will appear before any filename arguments.


Example:
panther% scramble >msg
This is a test of the emergency broadcasting system.
This is only a test.
^D
panther% cat msg
Tteytmhe  i.isebn stmrg   eo  ioras sfgdy   ecs atnat  hcse 
Tlhyi sa  itse sotn.
panther% scramble -u <msg
This is a test of the emergency broadcasting system.        
This is only a test.
panther% unscramble msg | scramble -cols 7
T   nanehaoecdgmi fmyc .st e as  etrbsy ishgrts steeoit 
T  hotinesls yti .sa 
panther%

Last modified: Tue Oct 29 11:00:49 EST 1996
Stephen Bloch / sbloch@boethius.adelphi.edu