Here is the code..........
//For gcc Compiler#include<stdio.h>
#include<string.h>
void main()
{
char send[100],encrypt[100],recieve[100];
int key; // ceaser cipher key
int i; //loop variableprintf("Enter the message\n"); //input the message
gets(send);
printf("Enter the key\n"); //input the message
scanf("%d",&key); //enter the key
//encryption
i=0;
while(send[i]!='\0')
{
/*To avoid any character from encryption as space or delimiter
if(send[i]==' ')
i++; */
send[i]=send[i]+key;
i++;
}
printf("The encypted message is\n");
puts(send);
//decryption
i=0;
while(send[i]!='\0')
{
/*To avoid any character from decryption as space or delimiter
if(send[i]==' ')
i++;
*/
send[i]=send[i]-key;
i++;
}
printf("The decrypted message is\n");
puts(send);
printf("\n");
}
No comments:
Post a Comment