# C Program For Caesar Cipher [Encryption & Decryption] | C Programming ## Caesar Cipher

The Caesar cipher is one of the earliest known and simplest ciphers. It is a type of substitution cipher in which each letter in the plaintext is 'shifted' a certain number of places down the alphabet. For example, with a shift of 1, A would be replaced by B, B would become C, and so on. The method is named after Julius Caesar, who apparently used it to communicate with his generals.
More complex encryption schemes such as the Vigenère cipher employ the Caesar cipher as one element of the encryption process. The widely known ROT13 'encryption' is simply a Caesar cipher with an offset of 13. The Caesar cipher offers essentially no communication security, and it will be shown that it can be easily broken even by hand.

### C Program For Caesar Cipher [Encryption]

```#include<stdio.h>
int main()
{
char msg, ch;
int i,key;
printf("Enter a plaintext \n");
gets(msg);
printf("Enter key");
scanf("%d",&key);
for(i=0;msg[i]!='\0';i++)
{
ch=msg[i];
if(ch>='a'&&ch<='z')
{
ch=ch+key;
if(ch>'z')
{
ch=ch-'z'+'a'-1;
}
msg[i]=ch;
}
else if(ch>='A'&&ch<'Z')
{
ch=ch+key;
if(ch>'Z')
{
ch=ch='Z'+'A'-1;
}
msg[i]=ch;
}
}
printf("Encrypted message: %s", msg);
return 0;
}```

### C Program For Caesar Cipher [Encryption]

```#include<stdio.h>
int main()
{
char msg, ch;
int i,key;
printf("Enter a Encrypted test \t");
gets(msg);
printf("Enter key \t");
scanf("%d",&key);
for(i=0;msg[i]!='\0';i++)
{
ch=msg[i];
if(ch>='a'&&ch<='z')
{
ch=ch-key;
if(ch<'a')
{
ch=ch+'z'-'a'+1;
}
msg[i]=ch;
}
else if(ch>='A'&&ch<'Z')
{
ch=ch+key;
if(ch<'A')
{
ch=ch+'Z'-'A'+1;
}
msg[i]=ch;
}
}
printf("Dycrypted message: %s", msg);
return 0;
}```