Question: Create a file named substitution.cpp . In this file, write a program that uses a substitution cipher to encrypt or decrypt its input. Your program
Create a file named substitution.cpp In this file, write a program that uses a substitution cipher to encrypt or decrypt its input.
Your program should take two command line arguments: the first argument must be either e for encryption or d for decryption The second argument must be a twentysixcharacter string containing each letter of the alphabet exactly once. If you run the program with the wrong number of arguments, or if any argument is invalid, it should print a usage message and exit with exit code :
julius@gallia lab$ substitution
USAGE: substitution edkey
If the command line arguments are valid, your program should read its input one line at a time, encrypting or decrypting each line and then printing the result. When encrypting, the letter A should be replaced with the first letter of the key, the letter B with the second, C with the third, and so on
julius@gallia lab$ substitution e egjhvakrzxpsynbtudmqiclfow
Outside of a dog, a book is man's best friend.
Biqmzhv ba e hbk e gbbp zm yen'm gvmq adzvnh.
Inside of a dog, it's too dark to read.
Znmzhv ba e hbk zqm qbb hedp qb dveh.
To make it easier to see what happened in the example above, you can line up the key with the unmodified alphabet. Each letter in the alphabet maps to the letter in the key at the same index:
abcdefghijklmnopqrstuvwxyz
egjhvakrzxpsynbtudmqiclfow
When decrypting, the first letter of the key should be replaced with A the second letter with B the third with C and so on
julius@gallia lab$ substitution d rptxnfhewgzdkicmbujsavloqy
Leq jecadx ln ervn r jsrixwih rukq?
Why should we have a standing army?
Pntrajn sers lrq ln jrvn kcinq ci terwuj.
Because that way we save money on chairs.
The letters of the key can be either upper or lower case or mixed as long as every letter of the alphabet is present. When encrypting and decrypting, match the case of the input. The key abcdefghijklmnopqrstuvwxyz will leave the input unchanged.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
