Reference no: EM133337882
Case: As a defensive programmer, we have to assume that the user will give us an input message on the command line which has characters which are not uppercase. But the Caesar algorithm can only encrypt uppercase letters. We need to deal with this.
(We need a function which takes as input the string of text that the user gave us on the command line. It will return a new string of text which is suitable for encryption by the Caesar cipher, i.e. it must be all uppercase letters.
Here is the (partial) API for this function. It will be called convert_to_Caesar(). It will take one argument: a string of text. It will return: a string of text. The letters in the argument will be processed as follows:
- uppercase letters will be left untouched
- lowercase letters will be converted to uppercase letters: 'a' →'A', 'b' → 'B' etc.
- the full stop '.' will be translated to the letter 'X' (as 'X' is rare, we can use it to separate sentences)
- all other letters in the argument will be discarded
You will design the algorithm for this function in pseudo-code, i.e. semi-English. The algorithm must have these properties:
- it must be guaranteed to stop and return a string regardless of the argument it is given
- it must obey the API contract defined above regardless of the argument it is given
- it must not crash or do unexpected things regardless of the argument it is given
- the algorithm must be written in simple enough steps that it can be translated into a computer language like Python
- the algorithm must be exact and well-defined, i.e. not open to interpretation
You will use English words like "if", "while" and "for" where they are suitable. These make sense to an English reader, but they also indicate programming structures such as sequence, selection and iteration to a programmer.)
Your task now is to create a single Python program called caesar.py. It will contain the two functions from the previous tasks. It will read in the user's inputs from the command line and perform the top-level pseudo-code. As you have already been given this pseudo-code, there is no need for you to write it.
- Step 1: Write Tests for the Program
This time, we are writing a full Python program (i.e. a software application) and not just a function. However, we can still test it, as the user will enter two input values on the command line( by using import sys and argv), and your program will output a piece of encrypted text.