-
Notifications
You must be signed in to change notification settings - Fork 7
/
Caesar Cipher
36 lines (35 loc) · 848 Bytes
/
Caesar Cipher
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
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k, i = 0;
char ch;
string s;
cin >> n >> s >> k;
while(i < n)
{
ch = s[i];
if(ch < 91 && ch > 64)
{
ch += k%26;
if(ch > 90)
{
ch -= 26;
}
}
else if(ch > 96 && ch < 123)
{
ch -= 96;
ch += k%26;
if(ch > 26)
{
ch -= 26;
}
ch += 96;
}
s[i] = ch;
i++;
}
cout << s;
return 0;
}