Question
Write a bash shell script named cipher.sh that encrypts and decrypts les based on a key given as an argument. A valid key is an
Write a bash shell script named cipher.sh that encrypts and decrypts les 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 le or text using this key such that all occurrences of the letter A in the text are replaced with the rst 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 rst converting everything in the le 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 dierent 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 le the result will be stored in and target is an optional argument that contains the path to the le 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 les 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 le (if given) does not exist.
You should include a comment at the beginning of the le (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 OUTPUT:
[ dservos5@cs2211b a2 ] $ cipher.sh Er ror : Need 3 or 4 arguments
[ dservos5@cs2211b a2 ] $ cipher. sh-a ZYXWVUTSRQPONMLKJIHGFEDCBA out Er ror : Fi r s t argument must be -e or -d
[ dservos5@cs2211b a2 ] $ cat out GSRH RH NB URIHG ORMV LU GVCG. R SLKV NB HXIRKG DLIPH! SRG XGIO-D GL HVMW Z VLU GL VCRG.
[ dservos5@cs2211b a2 ] $ ciphe r . sh -d ZYXWVUTSRQPONMLKJIHGFEDCBA decrypt out [ dservos5@cs2211b a2 ] $ cat decrypt THIS IS MY FIRST LINE OF TEXT. I HOPE MY SCRIPT WORKS! HIT CTRL-D TO SEND A EOF TO EXIT.
[ dservos5@cs2211b a2 ] $ c iphe r . sh -e NSZFXTOJCVQHLAGRIWMPYBKEUD output . txt textbook . txt
[ dservos5@cs2211b a2 ] $ cat output . txt 1 WXNHHCTX XENLRHXM YACE ZGAZXRPM NWX MCLRHX, SYP PJXU NWX NHMG NSMPWNZP, NAF 2 CPM GTPXA AGP GSBCGYM KJU N ZXWPNCA TXNPYWX CM JNAFHXF CA N RNWPCZYHNW KNU. 3 PJX LNMPXWU GT PJCM GRXWNPCAO MUMPXL WXIYCWXM N ZHXNW YAFXWMPNAFCAO GT PJXMX 4 ZGAZXRPM. C JNBX LNFX MYWX PJNP PJX QXU TXNPYWXM NWX XERHNCAXF ZHXNWHU PG 5 WXBXNH SGPJ PJXCW FXMCOA ZGAMCFXWNPCGAM NAF PJXCW WXHXBNAZX CA PJX WXNH 6 KGWHF. UGYHH TCAF PJNP LNAU XENLRHXM GT PJCM PXEP WXTXW PG WXNHHCTX 7 MCPYNPCGAM. 8 9 SGPJ N YMXWM NAF RWGOWNLLXWM OYCFX PJXWX NWX LNCAHU PKG ZNPXOGWCXM GT YACE 10 YMXWM: PJGMX KJG YMX CPM ANPCBX PGGHM, NAF GPJXWM KJG FXBXHGR PGGHM YMCAO 11 MJXHH MZWCRPM NAF PJX YACE MUMPXL ZNHH HCSWNWU. PJCM SGGQRWGSNSHU PJX GAHU 12 GAX GT CPM QCAFNFXIYNPXHU NFFWXMMXM SGPJ GT PJXMX MXOLXAPM SYP JNM N MCDX 13 PJNP CM ZGABXACXAP PG WXNF NAF ZNWWU. 14 15 PJX YMXW ZNPXOGWU CM MXWBXF SU PJX TCWMP 11 ZJNRPXWM, KJCZJ CM NFXIYNPX 16 TGW NA CAPWGFYZPGWU YACE ZGYWMX. PJX FXBXHGRXW CM N MJXHH GWMUMPXLM 17 RWGOWNLLXW KJG NHMG AXXFM PG QAGK JGK PJCAOM KGWQ, MNU, JGK N FCWXZPGWU CM 18 NTTXZPXF KJXA N TCHX CM ZWXNPXF GW HCAQXF. TGW PJXCW SXAXTCP, PJX CACPCNH 19 ZJNRPXWM ZGAPNCA MRXZCNH SGEXM PJNP RWGSX QXU ZGAZXRPM. PJCM NWWNAOXLXAP 20 MJGYHFAP NTTXZP PJX SXOCAAXW, KJG LNU IYCXPHU COAGWX PJXMX RGWPCGAM. YACE 21 MJCAXM PJWGYOJ ZJNRPXWM 16 , 17 , NAF 18 , MG PJXMX ZJNRPXWM NWX ZGLRYHMGWU 22 WXNFCAO TGWMUMPXLMRWGOWNLLXWM. 23 24 MPWGAO HXNWACAO NCFM PJX RXFNOGOCZNH NCFM NWX N MPWGAO TXNPYWX GT PJCM SGGQ. 25 PJXU JNBX BNWCGYM ANLXM, TGW XENLRHX, AGPX, ZNYPCGA, NAF PCR. C ZGAMCFXW 26 HCAYE PG SX NA CLRGWPNAP LXLSXW GT PJX YACE TNLCHU, MG C JNBX MXRNWNPXHU 27 JCOJHCOJPXF HCAYE TXNPYWXM YMCAO PJX RXAOYCA NM CFXAPCTCXW. 28 29 C FGAP NOWXX KCPJ PJX NRRWGNZJ NFGRPXF SU LNAU NYPJGWM GT PWXNPCAO XNZJ 30 MJXHH CA N MXRNWNPX ZJNRPXW. CAMPXNF, C JNBX FCMZYMMXF QXU ZGAZXRPM YMCAO 31 LNCAHU PJX SNMJ MJXHH. FXBCNPCGAM NWX NFFWXMMXF SU MXRNWNPX NMCFXM TGW PJX 32 Z MJXHH, QGWA, NAF SGYWAX MJXHHM.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started