-
Notifications
You must be signed in to change notification settings - Fork 4
/
rot13.cpp
64 lines (57 loc) · 1.75 KB
/
rot13.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <string.h>
using namespace std;
/*~~~~~ Declaring functions ~~~~~~ */
void encode();
void decode();
void choices() //Prompts Options to the user
{
int select;
string option[] = {"1. Encode","2. Decode","3. Exit" };
cout<<option[0]<<endl<<option[1]<<endl<<option[2]<<endl<<"Please Select an option: ";
cin>>select;
cin.ignore();
if(select == 1) encode();
if(select == 2) decode();
}
int main() // My Main function
{
choices();
}
void encode() //Starts Encoding
{
string msg;
int key = 13;
cout<<"Please Enter the plain text to Encrypt: ";
getline(cin,msg); //Takes plain text and saves it into msg
for(int i = 0; i < msg.size(); i++)
{
if(msg[i] >= char(65) && msg[i] <= char(77) || msg[i] >= char(97) && msg[i] <= char(109))
cout<< char(msg[i] + key);
else if(msg[i] > char(77) && msg[i] <= char(90) || msg[i] > char(109) && msg[i] <= char(122))
cout<< char(msg[i] - key);
else //for special characters
cout<<msg[i];
}
return;
}
void decode() //Starts Decoding
{
string msg;
int key = 13;
cout<<"Please Enter your Encrypted Message: ";
getline(cin, msg);
for(int i = 0; i < msg.size(); i++)
{
if (msg[i] >= char(65) && msg[i] <= char(77))
cout << char(msg[i] + key);
else if (msg[i] >= char(97) && msg[i] <= char(109))
cout << char(msg[i] + key);
else if(msg[i] > char(77) && msg[i] <= char(90))
cout << char(msg[i] - key);
else if(msg[i] > char(109) && msg[i] <= char(122))
cout << char(msg[i] - key);
else
cout << msg[i];
}
}