Reference no: EM131675
Write two programs.
• The first program will encipher a message using a keyword;
• The second program will decipher a message using a keyword.
Here is an example of a user interaction with the encipher program: Program output is in bold and user input is in italics.
Enter the keyword: Javabean
Enter the message (end with a blank line):
We are the Borg!
We jqe sde Amqc!
Resistance is futile!
Qerfrsjlve fr ntsfie!
Here is an example of a user interaction with the decipher program:
Enter the keyword: Javabean
Enter the message (end with a blank line):
We jqe sde Amqc!
We are the Borg!
Qerfrsjlve fr ntsfie!
Resistance is futile!
This is how enciphering works. First, the keyword is used to create a "ciphertext" alphabet. The keyword is written out with repeated letters removed, and then the remaining letters of the normal alphabet (the "plaintext" alphabet" are added). So from "Javabean", we get:
For this purpose, we ignore the case of the letters, treating them all as lowercase. Now to encipher a message, we replace each letter in the message with the corresponding ciphertext letter. Other characters, like spaces and punctuation, are left unchanged. Uppercase letters are converted to lowercase, substituted, and then converted to uppercase.
For example, the letter ‘B' is first converted to ‘b', which is the second letter in the plaintext alphabet, and then substituted with the second letter of the ciphertext alphabet, which is ‘a', and then converted back to uppercase, i.e. 'A'.
Deciphering is very similar, except that each letter is located in the ciphertext alphabet, and substituted with the corresponding letter from the plaintext alphabet. So, for example, ‘f' is the 9th letter in the ciphertext alphabet, so it is substituted with the 9th letter is the plaintext alphabet, which is ‘i'.