Write a program to implement character level encryption by monoalphabetic encryption method.
Program Code:
#include
#include
#include
#include
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
Shopping In MUMBAI
Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top.
Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.
Wednesday, January 7, 2009
Program to implement character level encryption by monoalphabetic encryption method.
Posted by ars at 9:04 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment