-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchar_str_main.cpp
More file actions
49 lines (39 loc) · 998 Bytes
/
char_str_main.cpp
File metadata and controls
49 lines (39 loc) · 998 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
48
#include <iostream>
#include <string>
using namespace std;
int main()
{
string alphabet_encoding{ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" };
string secret_code{ "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA" };
string user_input{};
string encoded_message{};
string decoded_message{};
cout << "Enter the alphabet encoding: ";
getline(cin, user_input);
cout << "Encoding....." << endl;
for (char a : user_input) {
int index = alphabet_encoding.find(a);
if (index != string::npos) {
encoded_message += secret_code.at(index);
}
else
{
encoded_message += a;
}
}
cout << "The encoded message is :" << encoded_message << endl;
cout << "Decoding....." << endl;
for (char p : encoded_message) {
int index2 = secret_code.find(p);
if (index2 != string::npos)
{
decoded_message += alphabet_encoding.at(index2);
}
else
{
decoded_message += p;
}
}
cout << "The decoded message is: " << decoded_message;
return 0;
}