In: Computer Science
Assignment 1 – Cipher
Situation.
You have been employed as a cipher clerk for the Secret Service agency. The radio operators have intercepted a foreign transmission, which is heavily encrypted. They are currently attempting to decrypt this information and have requested your help. The contents of the encrypted message are as follows:
Y [ZU [ XZWZ \ XXZjZ [ [ WWVWU
Ogaqkxpgbqbfiof! Cyw'ss bun!
Zqksxl cywd lnepwvs uozneh.
Qjc mgabiy nfx vmz-djrhkfalfq.
Xnjfx ai qjvi viqi uat pgw odjwp.
The radio operators have some information that they share with you, in their attempt to decrypt the message. The information is as follows:
‐ The first character of the entire message decrypts to the number ‘5’.
‐ It is known that the first line of the message forms some sort of combined encryption key that is required to decrypt the rest of the message.
‐ Except for the first line, special characters and spaces are not encrypted in the message. They can be skipped.
‐ XOR encryption was not done on the entire message but all other forms of numerical conversion and encryption are possibly used within the message.
‐ The use of upper‐case and lower‐case characters in the message are important for decryption.
Requirements:
You are required to programmatically implement an automatic decryption tool, using only C++ as your programming language. Your program must show how all steps of the decryption process are resolved, for any marks to be awarded. This is similar to the decryption method being done manually, by hand on paper, showing all steps and working as to how the final answer is obtained. The encrypted message must be stored as an input text file named “encrypted.txt” (without the quotation marks). Your implementation must contain:
‐ The entire operation of the program must use classes and its respective methods (class functions). Functions that are not implemented as class methods, except for the main function, will be disregarded for marking.
‐ The input text file must be read as an input argument to the program, from the system command prompt in the following format: program_name -input encrypyted.txt
‐ Your program must not crash due to incorrect inputs.
‐ Each step of the decryption process must be outputted to the system command prompt.
‐ Any numerical conversions must be done directly e.g. binary to octal, without the use of decimal. The use of intermediary bases will be disregarded for marking.
‐ An input argument named “‐silent” (without the quotation marks), is required to be implemented. This is to allow for a driver function to be called and only for the final answer to be outputted to the system command prompt. The format for this argument, coupled with the text file argument, can be seen below: program_name -input encrypted.txt -silent.
This should be coded using C++ programming language.
Encrypting and Decryption
There is a simple method of adding and subtracting the key values for encryption and decryption.
For encrypting a string key-value 5 is added to the ASCII values of the characters in the string. Similarily
for decrypting a string key-value 5 is subtracted to the ASCII value of the characters.
program
// Simple C++ program to encrypt and decrypt a string
#include<iostream.h>
#include<conio.h>
// using namespace std;
void main()
{
int i,x;
char str[100];
cout<<"Please enter a string :\t";
cin>>x;
// using switch case statements
switch(x)
{
// First case for encrypting a string
case 1:
for(i=0;(i<100 && str[i] ! = '\0');i++)
str[i] = str[i]-5;
\\ the key for encryption is 5 that is added to ASCII value
cout<<" \n Encrypted string : "<<str<<endl;
break;
// Second case for decrypting a string
case 2:
for(i=0;(i<100 && str[i] ! = '\0';i++)
str[i] = str[i]-2;
\\ the key for decryption is 5 that is subtracted from ASCII value
cout<<"\n Decrypted string : "<<str<<endl;
break;
default:
cout<<" \n Invalid Input \n";
}
getch();
}