Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases 28th British National Conference On Databases Bncod 28 Manchester Uk July 2011 Revised Selected Papers Lncs 7051

Authors: Alvaro A.A. Fernandes ,Alasdair J.G. Gray ,Khalid Belhajjame

2011th Edition

3642245765, 978-3642245763

More Books

Students also viewed these Databases questions