Headlines
Loading...
Data Communication network(DCN) Program to implement character level encryption by monoalphabetic encryption method.

Data Communication network(DCN) Program to implement character level encryption by monoalphabetic encryption method.

Write a program to implement character level encryption by monoalphabetic encryption method.

Program Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
 FILE *fp,*ft;
 char ch,s[100],x; 
 char ci[]={'k','c','p','s','v','m','h','f','d','b','u','w','q','n','r','y','t','j','o','i','x','e','l','a','z','g'};
 int i;
 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);
 }

 rewind(fp);
 while(1)
 {
  ch=fgetc(fp);
  if(ch==EOF)
  break;
  else
  {
   if(ch>=97 && ch<=122)
   {
    ch=ch-97;
    fputc(ci[ch],ft);

   }
   else if(ch>=65 && ch<=90)
   {
    ch=ch-65;
    fputc(toupper(ci[ch]),ft);
   }
   else
   fputc(ch,ft);
        }
 }
 rewind(ft);
 printf("\n\nCipher Text After Monoalphabetic Substitution Is:\n");
 printf("-------------------------------------------------\n\n");
 while(1)
 {
  ch=fgetc(ft);
  if(ch==EOF)
  break;
  printf("%c",ch);

 }
 rewind(fp);
 rewind(ft);
 printf("\n\n========Receiver Side==========\n\n");
 while(1)
 {
  ch=fgetc(ft);
  if(ch==EOF)
  break;
  else
  {
   if((ch>=97 && ch<=122) || (ch>=65 && ch<=90))
   {
    for(i=0;i<26;i++)
    {       x=ch;
     if(ci[i]==tolower(x))
     break;
    }
    if(isupper(ch))
     fputc(65+i,fp);
    else
     fputc(97+i,fp);
   }
   else
   fputc(ch,fp);
        }
 }
 rewind(fp);
 printf("\n\nMessage Sent From Sender Side Is\n");
 printf("-------------------------------------------------\n\n");
 while(1)
 {
  ch=fgetc(fp);
  if(ch==EOF)
  break;
  printf("%c",ch);

 }
 fclose(ft);
 fclose(fp);
 getch();
}

Output:

=========Sender Side============

Enter Few Lines Of Text

WARNING: it's a virus

Cipher Text After Monoalphabetic Substitution Is:
--------------------------------------------------
LKJNDNH: di'o k edjxo

========Receiver Side==========

Message Sent From Sender Side Is
-------------------------------------------------
WARNING: it's a virus
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***