Background When encoding messages one simple option is a substitution cipher. A substitution cipher replaces certain letters of the alphabet with other letters. For example, for each B in a message, a cipher may instead write Q and so on and so forth for the other letters of the alphabet. Unfortunately, a much more classic cipher was used last year, so this year I have produced a completely contrived one!!

Here is the logic. It is a variation on the idea, that you replace A with Z, B with Y, C with X and so on through the alphabet. In essence the first letter becomes the last letter. To make this arbitrarily annoying to program, I have decided to instead of just reversing from A to Z, the program should be able to arbitrarily shuffle from any start point to any end point.

For example: If I swap from C to F, all C’s becomes F’s, all D’s become E’s, all E’s become D’s, all F’s become C’s. All other letters remain unchanged. Now, fortunately Unix has a function that will greatly simplify this process called translate (shortened to tr). If given a few parameters, translate can perform an arbitrary cipher.

For example: tr ‘[abc]’ ‘[123]’ Will simply turn all a’s into 1’s, all b’s into 2’s and all c’s into 3’s. Translate also has a neat hyphen syntax for translating consecutive characters. tr ‘[a-m]’ ‘[A-M]’ … will convert the first 13 letters of the alphabet (a-m) from lower case to upper case! This won’t be particularly useful for this practical (or maybe it will?).

However translate is essential for those who don’t want to lose their minds.Task 1 Write a shell script called create_pattern.sh (the name must be EXACTLY correct) that takes two switches as parameters. The idea is that create_pattern will output a string suitable for translation that looks something like this: tr ‘[ABC]’ ‘[CBA]’ The switches are defined as follows: • -u: Where present (can be absent) will apply the rule to only UPPER CASE LETTERS • -s: Will be followed by two parameters, both integers representing the first and last letter (INCLUSIVE) which will be involved (and thus all the letters in between) where A=1 and Z=26 (whether upper or lower case). I

f it is still not clear, here is an example: • ./create_pattern -u -s 5 7 Will produce: • tr ‘[EFG]’ ‘[GFE]’ If it is still not clear, here is an example: • ./create_pattern -s 15 19 Will produce: • tr ‘[opqrs]’ ‘[srqpo]’ Please don’t do the opposite. I can’t be bothered writing two marking scripts WARNING: There is a very stupid way to do this practical. You could write a giant if-else statement for each possible pair of input numbers. That said, given there are ~650 legal combinations… I mean, why would you do this? It will not be met with… happiness (by that I mean good marks or… marks).

“Struggling with a similar assignment? We Can Help!”