How to Add the following 22 decryptions by looping through the cipherV vector, Instead of coding 22 more branch statements.
The complete list of cipher and normal characters to decrypt a message:
‘!’ > ‘a’ ‘^’ >’b’ ‘&’ >’c’ ‘*’ >’d’ ‘@’ >’e’ ‘(‘ > ‘f’ ‘)’ > ‘g’ ”-” > ‘h’ ‘#’ > ‘i’ ‘_’ > ‘j’ ‘=’ > ‘k’ ‘+’ > ‘l’ ‘[‘ > ‘m’
‘{‘ > ‘n’ ‘$’ > ‘o’ ‘]’ > ‘p’ ‘}’ > ‘q’ ‘;’ > ‘r’ ‘:’ > ‘s’ ‘,’ > ‘t’ ‘%’ > ‘u’ ‘<‘ > ‘v’ ‘.’ > ‘w’ ‘>’ > ‘x’ ‘/’ > ‘y’ ‘?’ > ‘z’
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<char> normalV(26);
vector<char> cipherV(26);
string toDec = “”;
string beenDec = “”;
normalV.at(0) = ‘n’; cipherV.at(0) = ‘{‘;
// Get secret message
do {
cout << “Enter a secret message: “;
getline(cin, toDec);
} while (toDec.length() == 0);
beenDec = toDec;
// Decrypt secret message
if (toDec.at(0) == cipherV.at(0)) {
beenDec.at(0) = normalV.at(0);
}
cout << “Decrypted message: ” << beenDec << endl;
return 0;
}


0 comments