-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (47 loc) · 1.94 KB
/
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
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
//
// Created by adbrei on 4/10/2020.
//
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string poem[22] = {"twinkle", "twinkle", "little", "bat",
"how", "i", "wonder", "what", "you're", "at",
"up", "above", "the", "world", "you", "fly",
"like", "a", "teatray", "in", "the", "sky"};
vector<char> encodedMsg = {'s', 't', 't', 'i', 'a', 'l', 'm', 'h'};
//vector<char> encodedMsg = {'s', 'o', 'o', 'o', 'j', 'g', 'd', 'b'};
// Print out msg
cout << endl << "POEM CODE" << endl;
cout << "------------------------------------" << endl << "Encrypted message: ";
for (char c: encodedMsg) {
cout << c << " ";
} cout << endl << "------------------------------------" << endl;
// Determine indicator word
vector<char> indicatorWord; // indicator is first char of msg
for (char x : poem[encodedMsg.at(0) - 97]) { // get indicator word from poem using 1st letter of msg
indicatorWord.push_back(x);
}
encodedMsg.erase(encodedMsg.begin()); // remove indicator char from msg
// Decrypt message
vector<char> decodedMsg(indicatorWord.size());
for (int j = 0; j < indicatorWord.size(); j++) {
char minChar = indicatorWord[0];
for (char x : indicatorWord) { // find minimum char
if (x < minChar) minChar = x;
}
for (int i = 0; i < indicatorWord.size(); i++) {
if (indicatorWord[i] == minChar) {
decodedMsg.at(i) = encodedMsg.at(j);
indicatorWord.at(i) = '{'; // '{' > lowercase alphabet
break; // Get out of loop before duplicate value are located
}
}
}
// Print out the decoded message!
cout << "Decrypted message: ";
for (char c : decodedMsg) cout << c << " ";
cout << endl << "------------------------------------" << endl;
return 0;
}