Practicle:1
AIM:- Implement Caesar cipher encryption-decryption
Source code:-C programming
Encryption
#include<stdio.h>
#include<conio.h>
int main()
int i, key;
char text[100],c;
printf("\nC Program to Perform Caesar Cipher (Decryption)");
printf("\nEnter Message : ");
gets(text);
printf("\nEnter Key : ");
scanf("%d", &key);
for(i = 0; text[i] != '\0'; ++i)
c = text[i];
if(c >= 'a' && c <= 'z')
c = c - key;
if(c < 'a')
{
c = c + 'z' - 'a' + 1;\
text[i] = c;
else if(c >= 'A' && c <= 'Z')
c = c - key;
if(c < 'A')
c = c + 'Z' - 'A' + 1;
text[i] = c;
printf("Decrypted text: %s", text);
getch();
Output:-
Decryption
#include<stdio.h>
#include<conio.h>
int main()
int i, key;
char text[100],c;
printf("\nC Program to Perform Caesar Cipher (Decryption)");
printf("\nEnter Message : ");
gets(text);
printf("\nEnter Key : ");
scanf("%d", &key);
for(i = 0; text[i] != '\0'; ++i)
c = text[i];
if(c >= 'a' && c <= 'z')
{
c = c - key;
if(c < 'a')
c = c + 'z' - 'a' + 1;
text[i] = c;
else if(c >= 'A' && c <= 'Z')
c = c - key;
if(c < 'A')
c = c + 'Z' - 'A' + 1;
text[i] = c;
printf("Decrypted text: %s", text);
getch();
}
Output:-