Question: Create a file named scytale.cpp . In this file, write a program that implements a scytale cipher. Your program should expect the same two command

Create a file named scytale.cpp. In this file, write a program that implements a scytale cipher.
Your program should expect the same two command line arguments as the Caesar cipher, but with the additional requirement that the second argument be greater that zero. If it is given invalid arguments, the program should print a usage message and exit with exit code 1:
[julius@gallia lab4]$ ./scytale
USAGE: scytale [-ed][key]
If given valid arguments, your program should read its input one line at a time, encrypt or decrypt each line as if on a scytale with the user-specified key as its circumference, and then print the result.
[julius@gallia lab4]$ ./scytale -e 3
'Twas brillig, and the slithy toves
'glT,iw taahsny d b trtoihvleel sis
Did gyre and gimble in the wabe;
Dd i tdgh iegm ybwrlaeeb eai;nn
You can think of a scytale as a grid. The height of the grid is the key provided by the user, and the width should be as small as possible while still containing the entire message. To encrypt, write a message in the grid from left to right, top to bottom, like English, then read it top to bottom, left to right.
If the length of the message isn't a multiple of the height of the grid, pad it with spaces until it is (and thus fills the entire grid); these spaces should be included in the output.
The first line of the example above corresponds to this grid:
'Twas brilli
g, and the s
lithy toves
To decrypt, write the message top to bottom, left to right, then read it left to right, top to bottom.
[julius@gallia lab4]$ ./scytale -d 7
Aiwtov lmehre lsreos ye g, m bo
All mimsy were the borogoves,
Atm huanhorstbdema ge etor.
And the mome raths outgrabe.
The first line of this example corresponds to this grid:
All m
imsy
were
the b
orogo
ves,
Note that when the key is one, or when it is greater than or equal to the length of the message, the input should be unchanged (although some padding spaces may be added).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!