Question: Question 5 (22 Marks) Write a bash shell script named cipher.sh that encrypts and decrypts files based on a key given as an argument. A

 Question 5 (22 Marks) Write a bash shell script named cipher.sh

Question 5 (22 Marks) Write a bash shell script named cipher.sh that encrypts and decrypts files based on a key given as an argument. A valid key is an ordering of the letters in the alphabet. That is a string containing the letters A to Z in any order that is not alphabetical. You can assume that all keys given to the script are valid (do not need to do error checking on keys) Your script will use the tr command to translate a given file or text using this key such that all occurrences of the letter A in the text are replaced with the first letter in the key, all occurrences of the letter B in the text are replaced with the second letter in the key, and so on up to and including Z and the last letter in the key Your script should deal with capitalization by first converting everything in the file or text to upper case before encrypting. You may assume that the key will be given in all upper case. Your script will work in two different modes, interactive or non-interactive, based on the number of arguments given to it. Your script will take the following arguments: cipher.sh mode key output [target] where mode is either "-e" or "-d" for encrypt or decrypt respectively, key is a string containing the 26 letters in the alphabet in some order, output is the file the result will be stored in and target is an optional argument that contains the path to the file to be encrypted or decrypted. If the target argument is not given, the text will be read in from the standard input Your script should not create or edit any files other than the output file You must do error checking and exit with a sensible exit status and error message in the following cases: The mode argument is not "-e or "-d" More than 4 or less than 3 arguments are given. The target file (if given) does not exist You should include a comment at the beginning of the file (under /bin/bash) that contains your name, student number and a one or two sentence description of what the script does. Also add at least two comments to lines in your script explaining what they do. Example Input Output dservos5 cs2211b a2]S cipher sh Err Need 3 or 4 arguments dservos5@cs2211b a2]8 cipher sh -a ZYXWVUISROPONMIKIHOFEDCBA out Err First argument must be-e or-d dservos5@cs2211b a2]8 cipher sh -d ZYXWVUISROPONMIKIHOFEDCBA out bad.fail.name.txt Erro Target le does not exist Question 5 (22 Marks) Write a bash shell script named cipher.sh that encrypts and decrypts files based on a key given as an argument. A valid key is an ordering of the letters in the alphabet. That is a string containing the letters A to Z in any order that is not alphabetical. You can assume that all keys given to the script are valid (do not need to do error checking on keys) Your script will use the tr command to translate a given file or text using this key such that all occurrences of the letter A in the text are replaced with the first letter in the key, all occurrences of the letter B in the text are replaced with the second letter in the key, and so on up to and including Z and the last letter in the key Your script should deal with capitalization by first converting everything in the file or text to upper case before encrypting. You may assume that the key will be given in all upper case. Your script will work in two different modes, interactive or non-interactive, based on the number of arguments given to it. Your script will take the following arguments: cipher.sh mode key output [target] where mode is either "-e" or "-d" for encrypt or decrypt respectively, key is a string containing the 26 letters in the alphabet in some order, output is the file the result will be stored in and target is an optional argument that contains the path to the file to be encrypted or decrypted. If the target argument is not given, the text will be read in from the standard input Your script should not create or edit any files other than the output file You must do error checking and exit with a sensible exit status and error message in the following cases: The mode argument is not "-e or "-d" More than 4 or less than 3 arguments are given. The target file (if given) does not exist You should include a comment at the beginning of the file (under /bin/bash) that contains your name, student number and a one or two sentence description of what the script does. Also add at least two comments to lines in your script explaining what they do. Example Input Output dservos5 cs2211b a2]S cipher sh Err Need 3 or 4 arguments dservos5@cs2211b a2]8 cipher sh -a ZYXWVUISROPONMIKIHOFEDCBA out Err First argument must be-e or-d dservos5@cs2211b a2]8 cipher sh -d ZYXWVUISROPONMIKIHOFEDCBA out bad.fail.name.txt Erro Target le does not exist

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!