Decrypting a Secret Message
include
include
include
using namespace std;
int main() {
vector normalV(26);
vector cipherV(26);
string toDec = “”;
string beenDec = “”;
// Message letters and Cipher Symbol Vectors
normalV.at(0) = 'a'; cipherV.at(0) = '!';
normalV.at(1) = 'b'; cipherV.at(1) = '^';
normalV.at(2) = 'c'; cipherV.at(2) = '&';
normalV.at(3) = 'd'; cipherV.at(3) = '*';
normalV.at(4) = 'e'; cipherV.at(4) = '@';
normalV.at(5) = 'f'; cipherV.at(5) = '(';
normalV.at(6) = 'g'; cipherV.at(6) = ')';
normalV.at(7) = 'h'; cipherV.at(7) = '-';
normalV.at(8) = 'i'; cipherV.at(8) = '#';
normalV.at(9) = 'j'; cipherV.at(9) = '_';
normalV.at(10) = 'k'; cipherV.at(10) = '=';
normalV.at(11) = 'l'; cipherV.at(11) = '+';
normalV.at(12) = 'm'; cipherV.at(12) = '[';
normalV.at(13) = 'n'; cipherV.at(13) = '{';
normalV.at(14) = 'o'; cipherV.at(14) = '$';
normalV.at(15) = 'p'; cipherV.at(15) = ']';
normalV.at(16) = 'q'; cipherV.at(16) = '}';
normalV.at(17) = 'r'; cipherV.at(17) = ';';
normalV.at(18) = 's'; cipherV.at(18) = ':';
normalV.at(19) = 't'; cipherV.at(19) = ',';
normalV.at(20) = 'u'; cipherV.at(20) = '%';
normalV.at(21) = 'v'; cipherV.at(21) = '<';
normalV.at(22) = 'w'; cipherV.at(22) = '.';
normalV.at(23) = 'x'; cipherV.at(23) = '>';
normalV.at(24) = 'y'; cipherV.at(24) = '/';
normalV.at(25) = 'z'; cipherV.at(25) = '?';
// Get secret message
do {
cout << "Enter a secret message: ";
getline(cin, toDec);
} while (toDec.length() == 0); // Continues prompting for "Enter a secret message" until something is entered
beenDec = toDec;
// Loop Counter Variables
int i = 0;
int j = 0;
// Decrypt secret message
for (i = 0; i < toDec.size(); ++i) { // Loops below process for each charcter in the inputted message
for (j = 0; j < 26; ++j) { // Loops the if statement conversion for any letter in the "normalV" vector
if (toDec.at(i) == cipherV.at(j)) {
beenDec.at(i) = normalV.at(j);
}
}
}
cout << "Decrypted message: " << beenDec << endl;
return 0;
}
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"
