-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathcaesarCipher.cpp
More file actions
47 lines (36 loc) · 859 Bytes
/
Copy pathcaesarCipher.cpp
File metadata and controls
47 lines (36 loc) · 859 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
int main(){
string input;
cout << "Input string : ";
cin >> input;
int key;
cout << "Input key : ";
cin >> key;
for(int i=0; i<input.length(); i++){
int ascii = input[i];
// check if the char is in lowercase
if(ascii >= 97 and ascii <= 122){
ascii = ascii+key;
if(ascii > 122){
ascii = (ascii % 122) + 96;
}
char output = ascii; // convert ascii to char
cout << output;
//check if the char is in uppercase
} else if(ascii >= 65 and ascii <= 90){
ascii = ascii+key;
if(ascii > 90){
ascii = (ascii % 90) + 64;
}
char output = ascii; // convert ascii to char
cout << output;
// if the char is not alphabet, do nothing
} else {
cout << input[i];
}
}
// List char to ascii number
// a 97 --- z 122
// A 65 --- Z 90
}