-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
33 lines (33 loc) · 989 Bytes
/
main.cpp
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
#include<iostream>
#include<string>
using namespace std;
int main()
{
/*
Dorateatcheese message solver
This one is using ROT13.
*/
string s;
int offset;
cout<<"Enter the encoded message: ";
getline(cin>>ws,s);
cout<<"Enter offset: ";
cin>>offset;
cout<<"Decoded message: ";
for(int i=0; i<=s.size(); i++){
if(s[i] >= 'a' && s[i] <='z'){
if(s[i] + offset >= 'a' && s[i] + offset <='z')
cout<<char(s[i] + offset);
else if (s[i] - offset >= 'a' && s[i] - offset <='z')
cout<<char(s[i] - offset);
}
else if (s[i] >= 'A' && s[i] <='Z'){
if(s[i] + offset >= 'A' && s[i] + offset <='Z')
cout<<char(s[i] + offset);
else if (s[i] - offset >= 'A' && s[i] - offset <='Z')
cout<<char(s[i] - offset);
}
else if (s[i] == ' ') cout<<" ";
else cout<<s[i];
}
}