Problem Statement:
Program to implement Caesar Cipher.
Note: Caesar Cipher is an encryption technique in cryptography. In this technique, we are given a text which we have to encrypt by shifting the characters by some fixed number of positions.
#include<stdio.h>
int main(){
char text[50],encrypt[50];
int n,i;
gets(text);
scanf("%d",&n);
for(i=0;text[i]!='\0';i++){
if(text[i]>='a' && text[i]<='z'){
if(text[i]+n>'z'){
encrypt[i] = (text[i]+n)-26;
}else{
encrypt[i] = text[i]+n;
}
}
if(text[i]>='A' && text[i]<='Z'){
if(text[i]+n>'Z'){
encrypt[i] = (text[i]+n)-26;
}else{
encrypt[i] = text[i]+n;
}
}
}
encrypt[i]='\0';
puts(encrypt);
return 0;
}
int main(){
char text[50],encrypt[50];
int n,i;
gets(text);
scanf("%d",&n);
for(i=0;text[i]!='\0';i++){
if(text[i]>='a' && text[i]<='z'){
if(text[i]+n>'z'){
encrypt[i] = (text[i]+n)-26;
}else{
encrypt[i] = text[i]+n;
}
}
if(text[i]>='A' && text[i]<='Z'){
if(text[i]+n>'Z'){
encrypt[i] = (text[i]+n)-26;
}else{
encrypt[i] = text[i]+n;
}
}
}
encrypt[i]='\0';
puts(encrypt);
return 0;
}
SAMPLE INPUT:
hello
3
SAMPLE OUTPUT:
khoor
hello
3
SAMPLE OUTPUT:
khoor