Create a program that encrypts a plain text into a cipher text and decrypts a cipher text into a plain text via an
encryption/decryption key.
The program provides three options: [1] Encrypt [2] Decrypt [3] Exit.
If option 1 is selected, the program would prompt for the plain text to encrypt and the encryption key to be
used. The program would then display the encrypted cipher text. The user would be provided an option to save the
cipher text in a text file. If the user opts to do so, the program would prompt for the file name.
If option 2 is selected, the program would prompt for the cipher text to decrypt and the decryption key to be
used. The program would then display the decrypted plain text.
If option 3 is selected, the program terminates.
Encryption Algorithm:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Each letter in the plain text is replaced by a letter some fixed number of positions down the alphabet based on
the corresponding letter in the encryption key.
For example, we will encrypt the plaintext “i love you” using the encryption key “love”. We start with the first
character of the plain text which is ‘i’. First, we’ll look at the corresponding character in the encryption key, which
happens to be, in this case, also the first character: ‘l’. We then count the position of ‘l’ relative to the starting letter of
the alphabet, which is ‘a’. Character ‘l’ is 11 places away from ‘a’.
Now we go back to our plain text character, ‘i’. We will now replace ‘i’ with the 11th letter relative to it to the
right which is ‘t’. We have now converted a plain text character to its cipher equivalent. We then move to the next letter
of the plain text (‘l’) and its corresponding letter in the encryption key (‘o’) and repeat the encryption process.
If we’ve reached the final letter in the encryption key and there are still unencrypted letters left in the plain text,
we just roll back to the key’s first letter and continue the process. For instance, the fifth letter in “i love you” is ‘e’. Since
our encryption key “love” only contains 4 characters, we’ll go back to the starting letter ‘l’ and use it as the encryption
key for plain text character ‘e’.
Similarly, if we’ve reached the final letter of the alphabet (‘z’) but still haven’t finished encrypting the plain text
character, we just continue the counting of positions at the start of the alphabet (‘a’). For instance, encryption key
character ‘v’ is 21 places away from ‘a’. If we use this shift number to encrypt plain text character ‘o’, we’ll reach the
end of the alphabet by the 11th shift. In this case, we’ll just continue the next shift count at ‘a’. Thus, the resulting cipher
character is ‘j’.