-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
187 lines (174 loc) · 4.75 KB
/
Copy pathmain.cpp
File metadata and controls
187 lines (174 loc) · 4.75 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Title: Cipher_Code_Decryption.cpp
// course: Computational Problem Solving I (CPET-121)
// Developer: Miftahul Huq (Freshmen at RIT)
// Date: 08/07/2020
// Description: The following code decrypts (decode) a message that was
// encoded using a variation of the Baconian Chipher. Each file
// contians a phrase, and with them contains a hidden message
// based on the capitalization of the letters message. The
// below code can seperately decode the hidden message that is
// within them.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Name: nonAlphaChecker()
// Input: (1) Call-by-reference string variable and file
// Output: (1) String withoug any nonalphabet letters
// Purpose: Take any nonalphabet letters from the user string
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
string nonAlphaChecker(string& userString, ifstream& inFile) {
char data;
inFile.get(data);
while (!inFile.eof()) {
if (isalpha(data)) {
userString.push_back(data); // Adds the character
}
inFile.get(data);
}
return userString;
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Name: messageDecoder()
// Input: (1) String variable
// Output: (1) String
// Purpose: decode the string according to the Cipher Code Decryption
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void messageDecoder (string userString) {
unsigned i;
string encodedLetters;
string substring;
/* code below doesn't use the last 4 character and
make use of what the code can use */
while (userString.size() >= 5) {
substring = userString.substr(0, 5);
userString.erase(0, 5);//Delets the 5 character that in use
for (i = 0; i < 5; ++i) {
if (isupper(substring.at(i))) {
encodedLetters.push_back('U');
}
else {
encodedLetters.push_back('L');
}
}
if (encodedLetters == "UUUUU") {
cout << 'A';
}
else if (encodedLetters == "UUUUL") {
cout << 'B';
}
else if (encodedLetters == "UUULU") {
cout << 'C';
}
else if (encodedLetters == "UUULL") {
cout << 'D';
}
else if (encodedLetters == "UULUU") {
cout << 'E';
}
else if (encodedLetters == "UULUL") {
cout << 'F';
}
else if (encodedLetters == "UULLU") {
cout << 'G';
}
else if (encodedLetters == "UULLL") {
cout << 'H';
}
else if (encodedLetters == "ULUUU") {
cout << 'I';
}
else if (encodedLetters == "ULUUL") {
cout << 'J';
}
else if (encodedLetters == "ULULU") {
cout << 'K';
}
else if (encodedLetters == "ULULL") {
cout << 'L';
}
else if (encodedLetters == "ULLUU") {
cout << 'M';
}
else if (encodedLetters == "ULLUL") {
cout << 'N';
}
else if (encodedLetters == "ULLLU") {
cout << 'O';
}
else if (encodedLetters == "ULLLL") {
cout << 'P';
}
else if (encodedLetters == "LUUUU") {
cout << 'Q';
}
else if (encodedLetters == "LUUUL") {
cout << 'R';
}
else if (encodedLetters == "LUULU") {
cout << 'S';
}
else if (encodedLetters == "LUULL") {
cout << 'T';
}
else if (encodedLetters == "LULUU") {
cout << 'U';
}
else if (encodedLetters == "LULUL") {
cout << 'V';
}
else if (encodedLetters == "LULLU") {
cout << 'W';
}
else if (encodedLetters == "LULLL") {
cout << 'X';
}
else if (encodedLetters == "LLUUU") {
cout << 'Y';
}
else if (encodedLetters == "LLUUL") {
cout << 'Z';
}
else if (encodedLetters == "LLULU") {
cout << '.';
}
else if (encodedLetters == "LLULL") {
cout << ';';
}
else if (encodedLetters == "LLLUU") {
cout << '!';
}
else if (encodedLetters == "LLLUL") {
cout << '?';
}
else if (encodedLetters == "LLLLU") {
cout << '0';
}
else if (encodedLetters == "LLLLL") {
cout << ' ';
}
// Delets the letters to append new ones during this loop
encodedLetters.erase(0, 5);
}
}
int main() {
string userString;
ifstream inFile;
string userInput;
cin >> userInput;
inFile.open(userInput.c_str());
if (!inFile.is_open()) {
cout << "DATA FILE DID NOT OPEN... Program Terminated";
exit(1); // Terminated code if the file cannot be opened
}
else {
nonAlphaChecker(userString,inFile);
messageDecoder(userString);
}
inFile.close();
return 0;
}