ENS EN.
NO:206400316171
Caser Cipher Encryption Algorithm
#include<stdio.h>
#include<conio.h>
int main()
char str[100];
int i,key;
printf("Enter the Message to Encrption: ");
gets(str);
printf("Enter the key: ");
scanf("%d",&key);
for(i=0;str[i];i++)
if(str[i]==' ')
continue;
else if(str[i]>='a' && str[i]<='z')
if(str[i]+key > 'z')
str[i]=str[i]+key-26;
else
str[i]=str[i]+key;
else if(str[i]>='A' && str[i]<='Z')
if(str[i]+key > 'Z')
str[i]=str[i]+key-26;
else
str[i]=str[i]+key;
printf("The Encrypted Message is: ");
puts(str);
}
ENS EN.NO:206400316171
Output:
ENS EN.NO:206400316171
Caser Cipher Decryption Algorithm
#include<stdio.h>
int main()
char message[100], ch;
int i, key;
printf("Enter a message to decrypt: ");
gets(message);
printf("Enter key: ");
scanf("%d", &key);
for(i = 0; message[i] != '\0'; ++i)
ch = message[i];
if(ch >= 'a' && ch <= 'z')
ch = ch - key;
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
message[i] = ch;
else if(ch >= 'A' && ch <= 'Z')
ch = ch - key;
if(ch < 'A'){
ch = ch + 'Z' - 'A' + 1;
message[i] = ch;
printf("Decrypted message: %s", message);
return 0;
}
ENS EN.NO:206400316171