Write a Program to perform Encryption & Decryption using Monoalphabetic
Cipher technique.
Cipher technique.
Code:
#include<stdio.h>
#include<conio.h>
char pt[50],ct[50],ch,dt[50];
char alpha[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'};
char sub[26]={'q','w','e','r','t','y','u','i','o','p','a','s','d',
'f','g','h','j','k','l','z','x','c','v','b','n','m'};
int i,j;
void main()
{
clrscr();
printf("Enter plain text:");
gets(pt);
for(i=0;i<strlen(pt);i++)
{
ch=pt[i];
for(j=0;j<26;j++)
{
if(alpha[j]==ch)
{
ct[i]=sub[j];
}
}
}
ct[i]='\0';
for(i=0;i<strlen(ct);i++)
{
ch=ct[i];
for(j=0;j<26;j++)
{
if(sub[j]==ch)
{
dt[i]=alpha[j];
}
}
}
dt[i]='\0';
printf("\nciphetext is:");
for(i=0;i<strlen(ct);i++)
{
printf("%c",ct[i]);
}
printf("\ndecriptedtext is:");
for(i=0;i<strlen(dt);i++)
{
printf("%c",dt[i]);
}
getch()
}
No comments:
Post a Comment