-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCaesar-Cipher.c
More file actions
28 lines (25 loc) · 831 Bytes
/
Caesar-Cipher.c
File metadata and controls
28 lines (25 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include<stdlib.h>
int main(){
int N,K;
scanf("%d",&N);
unsigned char* S = (char *)malloc(10240 * sizeof(char)); //malloc () is used for dynamic memory allocation.
scanf("%s",S);
scanf("%d",&K);
for(int i=0;i<N;i++)
{
if(S[i] >= 97 && S[i] <= 122) //For small letters
{
S[i]=S[i]+K; //ASCII value increasing.
while(S[i]>122)
S[i]=(S[i]%122)+97-1; //after z it will start from a agin.
}
else if(S[i] >= 65 && S[i] <= 90) //For capital letters
{
S[i]=S[i]+K;
while(S[i]>90)
S[i]=(S[i]%90)+65-1; // after Z it will start from A again.
}
} printf("%s",S);
return 0;
}