Data Communication network(DCN) Program to implement character level encryption by polyalphabetic encryption method.
Write a program to implement character level encryption by polyalphabetic encryption method.
Program Code:
#include<stdio .h="">
#include<conio .h="">
#include<string .h="">
#include<ctype .h="">
void main()
{
FILE *fp,*ft;
unsigned char ch;
char s[100],x;
int ci[10],i,n;
clrscr();
printf("=========Sender Side============\n\n");
fp=fopen("cipher.txt","w+");
ft=fopen("cipher1.txt","w+");
if(fp==NULL)
{
printf("\nCannot Open File");
getch();
exit(0);
}
printf("\nEnter Few Lines Of Text\n\n");
while(strlen(gets(s))>0)
{
fputs(s,fp);
fputs("\n",fp);
}
printf("How Many Keys(Periods)=");
scanf("%d",&n);
printf("Enter %d Key Elements\n",n);
for(i=0;i<n break="" ch="" ci="" d="" else="" fp="" i="0;" if="" rewind="" scanf="" while="" x="=EOF)">=97 && ch<=122)
{
ch=ch+(ci[i]%26);
if(ch>122)
ch=96+(ch-122);
i++;
}
else if(ch>=65 && ch<=90)
{
ch=ch+(ci[i]%26);
if(ch>90)
ch=64+(ch-90);
i++;
}
fputc(ch,ft);
}
}
rewind(ft);
printf("\n\nCipher Message After Polyalphabetic Substitution Is:\n");
printf("-------------------------------------------------\n\n");
while(1)
{
x=fgetc(ft);
if(x==EOF)
break;
printf("%c",x);
}
rewind(fp);
rewind(ft);
printf("\n\n========Receiver Side==========\n\n");
i=0;
while(1)
{
if(i==n)
i=0;
x=fgetc(fp);
ch=x;
if(x==EOF)
break;
else
{
if(ch>=97 && ch<=122)
{
ch=ch-(ci[i]%26);
if(ch<97 ch="" else="" i="" if="">=65 && ch<=90)
{
ch=ch-(ci[i]%26);
if(ch</97></n></ctype></string></conio></stdio>