-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhrase.cpp
135 lines (119 loc) · 3.09 KB
/
Phrase.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "Phrase.h"
Phrase::Phrase() {
cout << "Default constructor" << endl;
}
Phrase::Phrase(const string &text, const string &auth) {
author = auth;
input = text;
char puncMarks[] = " .,:;?()[]\"'.!/-_*#";
for (char i : text) {
char c = tolower(i);
textVec.emplace_back(1, c);
}
for (const string &j : textVec) {
bool dup = false;
bool special = false;
for (auto &symbol : symbols) {
if (j == get<0>(symbol)) {
dup = true;
}
}
for (char l : puncMarks) {
if (j == string(1, l)) {
special = true;
}
}
if (!dup && !special) {
string sym = SymSel();
symbols.emplace_back(j, sym);
userEdit.emplace_back(sym, sym);
}
}
SymSel();
Encryption();
}
Phrase::~Phrase() {
//cout << "Destructor" << endl;
}
void Phrase::Display() {
for (const string &i : textVec) {
cout << i;
}
cout << " -" << GetAuthor() << endl;
}
string Phrase::SymSel() {
unsigned int i = rand() % (characters.size()) + 0;
string sel = characters[i];
characters.erase(characters.begin() + i);
return sel;
}
void Phrase::Encryption() {
for (auto &t : textVec) {
for (auto &symbol : symbols) {
if (t == get<0>(symbol)) {
t = get<1>(symbol);
}
}
}
}
bool Phrase::WinCheck() {
bool win = true;
for (int i = 0; i < symbols.size(); ++i) {
if (get<0>(symbols[i]) != get<0>(userEdit[i])) {
win = false;
}
}
return win;
}
tuple<int, string> Phrase::Menu() {
tuple<int, string> cPick;
char cSel;
bool exit = false;
string sSel;
make_tuple(0, " ");
do {
cout << "Select character to replace or enter \"1000\" to exit:" << endl;
for (int i = 0; i < userEdit.size(); ++i) {
cout << i + 1 << '\t' << get<1>(userEdit[i]) << endl;
}
cin >> get<0>(cPick);
if (get<0>(cPick) != 1000){
if ((get<0>(cPick) < 1) || (get<0>(cPick) > symbols.size())){
exit = true;
}
} else {
exit = false;
}
} while (exit);
if (get<0>(cPick)!= 1000){
get<0>(cPick)--;
cout << "Enter replacement character:" << endl;
cin >> cSel;
cSel = _tolower(cSel);
sSel = string(1, cSel);
for (int i = 0; i < userEdit.size(); ++i) {
if ((sSel == get<1>(userEdit[i])) && (i != (get<0>(cPick)))){
sSel = "ʭ";
}
}
get<1>(cPick) = sSel;
} else {
get<1>(cPick) = 'q';
}
return cPick;
}
void Phrase::Decryption(tuple<int, string> userSel) {
get<0>(userEdit[get<0>(userSel)]) = get<1>(userSel);
for (auto &i : textVec) {
if (i == get<1>(userEdit[get<0>(userSel)])) {
i = get<1>(userSel);
}
}
get<1>(userEdit[get<0>(userSel)]) = get<1>(userSel);
}
string Phrase::GetAuthor() {
return author;
}
string Phrase::GetInput() {
return input;
}