PROGRAM DESCRIPTION: The purpose of this programming project is write a C++ program to implement a simple poly alphabetic cryptosystem that incorporates topics related to file Uo. In particular, this programming assignment will read an input fe, encrypt or decrypt the fie based onthe requested operation, and write the results to an output file REQUIREMENTS As with all programs in this course, your program\'s output should initially display the department and course number, your name, your EUID. and your e-mail address. This functionality will be implemented using a function. Your will prompt the user whether he/she would like to encrypt ordecrypt a file. a valid response is not input, you are to repeatedly re-prompt the user until a valid response is input. You wil then prompt the user to enter the name of the input file to read from and the output file to write the resulting plaintext or ciphertext as appropriate. If there is a problem opening the file, you wil display a meaningful error and exit the program using the appropriate exit status. You may assume that the length of the file name does not exceed 25 characters (26 with the terminating null character). If there are no errors causing you to terminate the program, you wil then call a function that will process the input file (ie.. encrypt or decrypt the input file, as appropriate) and write the results to an output file based on the folowing requirements: 1. You wil prompt the user to enter a 5-letter key that wil be used to encrypt or decrypt the file as appropriate for the operaton. You must read this 5- letter key as 5 separate characters i e.. you must five different char variables to account for each letter in the key). You may assume that the 5-letter key consists of alphabetic characters, but they may be entered as either uppercase or lowercase. Ultimately, you may treat each character as uppercase so that your shift wil have a range of 0- 25 (where A 0, B 1, etc.) 2. The files that you wil encrypt or decrypt will only contain uppercase alphabetic characters (A 2), lowercase alphabetic characters (a z) and whitespace, which may indude any white space character such as a blank space a tab, or a newfne character 3. The user-defined function to process the input and output files should accept two parameters as a minimum, the input fie stream and the output file stream, but it may utilize additional parameters as needed. You must process each file character-by-character (Le.. using the get and put member funcSons)
#include<conio.h>
#include<stdio.h>
char ct[20],pt[20],rf[20],k[26];
int i,j,l;
void encrypt();
void decrypt();
int select(int);
void getd();
void display2();
int display();
void main()
{
int c;
do{
clrscr();
f1:
display();
printf(“Enter Your Choice:”);
scanf(“%d”,&c);
if(c>4 || c<1){
clrscr();
printf(“\ Enter proper value\ ”);
goto f1;
}
select(c);
}while(c!=4);
getch();
}
int display(){
printf(“polyalphabetic program\ ”);
printf(“———————–\ ”);
printf(” option Functions\ ”);
printf(“———————–\ ”);
printf(” [1] Enter The Text\ ”);
printf(” [2] Encrypted Text\ ”);
printf(” [3] Decrypted Text\ ”);
printf(” [4] Exit\ ”);
printf(“———————–\ ”);
return 0;
}
int select(int c){
int i;
switch(c)
{
case 1:{clrscr();
display();
fflush(stdin);
getd();
display2();
for(i=0;ct[i]!=”;i++)
ct[i]=”;
break;
}
case 2:{clrscr();
display();
encrypt();
break;
}
case 3:{clrscr();
display();
decrypt();
break;
}
case 4: break;
}
return c;
}
void getd(){
printf(“Enter the key:”);
gets(k);
printf(“Enter the Plaintext:”);
gets(pt);
}
void display2(){
clrscr();
display();
printf(“key:%s\ Plaintext:%s\ ”,k,pt);
getch();
}
void encrypt(){
//ct=(26+((65-k)+(65-pt)))%26;
int l1=strlen(pt);
display2();
for(i=0,l=0;i<l1;i++){
if(pt[i]==’ ‘)
ct[i]=pt[i];
else{
j=l%3;
ct[i]=65+((26+((k[j]-65)+(pt[i]-65)))%26);
l++;
}
}
printf(“ciphertext:%s”,ct);
getch();
}
void decrypt(){
//rf=(26+((65-ct)+(65-k)))%26;
int l1=strlen(pt);
printf(“key:%s\ ciphertext:%s\ ”,k,ct);
for(i=0,l=0;i<l1;i++){
if(ct[i]==’ ‘)
rf[i]=ct[i];
else{
j=l%3;
rf[i]=65+((26+((ct[i]-65)-(k[j]-65)))%26);
l++;
}
}
printf(“\ palintext:%s”,rf);
getch();
}