Background:

Cryptography is the study of techniques for securing data for communication in the presence of adversaries. The data or message that is to be communicated is encrypted (converted from a readable state to apparent nonsense) by the originator. The encryption technique is shared only with the receiver of the message so that only he can decrypt the message.

One of the early forms of encryption is that used by Julius Caesar of the Roman Empire where he would encrypt his messages to his military generals. He would shift each letter in his original message by 3 places, which would appear meaningless in case it was intercepted. For example, if his original message was:

MEET AT THE ELEPHANT LAKE AFTER SUNSET ON SUNDAY

He would substitute each letter by the letter 3 places after it in the alphabet. Thus, the encrypted message would become:

PHHW DW WKH HOHSKDQW ODNH DIWHU VXQVHW RQ VXQGDB

The receiver of the message would then shift the letters 3 places backwards to retrieve the original message.

Assignment:

Write 2 programs:

1. An encryptor that will encrypt the message according to Caesars technique mentioned above. The encryptor will read the message from the keyboard and save the encrypted message into a file called data.encrypt. It should be able to accept a message that consists of multiple lines. Assume that the message only consists of the upper case letter AZ, the space character, and the newline character. You will only shift the letters and leave the space and newline characters as is. Make sure to shift the letters X, Y, and Z to A, B, and C.

2. A decryptor that the receiver of the encrypted message can use to decrypt the message. The decryptor will read the saved data.encrypt file and display the decrypted message on the screen.

Note: You may also choose to write one program and ask the user whether he wants to encrypt or decrypt

Hint:

1. You may wish to follow the following design for the encryptor:

• Ask user to enter the message to encrypt
• Open data.encrypt file
• For each line that the user enters, do the following:
• For each character that is in the line, do the following:
• If the character is a space, leave it alone
• Otherwise, replace the character with the character that is 3 spaces after it in the alphabet
• Write the line to the data.encrypt file
• Close file

2. And the following design for the decryptor:

• Open data.encrypt file
• For each line that is read from the file, do the following:
• For each character that is in the line, do the following:
• If the character is a space, leave it alone
• Otherwise, replace the character with the character that is 3 spaces before it in the alphabet
• Write the line to the screen
• Close file

3. The following functions may be useful:

• getline (cin, line) reads a line of text from the keyboard and stores it in the string variable called line
• getline (inputFile, line) reads a line of text from the ifstream variable called inputFile and stores it in the string variable called line
• line.length() returns the length of the characters stored in the string variable called line
• line.at(i) returns the character stored at position i in the string variable called line