C++ Decypher message

label Computer Science
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

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;
}

May 28th, 2015

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    const int setNum = 26;
    vector<char> normalV(setNum);
    vector<char> cipherV(setNum);
    string toDec = "";
    string beenDec = "";
    int i = 0;

    normalV.at(i) = 'a'; cipherV.at(i) = '!'; ++i;
    normalV.at(i) = 'b'; cipherV.at(i) = '^'; ++i;
    normalV.at(i) = 'c'; cipherV.at(i) = '&'; ++i;
    normalV.at(i) = 'd'; cipherV.at(i) = '*'; ++i;
    normalV.at(i) = 'e'; cipherV.at(i) = '@'; ++i;
    normalV.at(i) = 'f'; cipherV.at(i) = '('; ++i;
    normalV.at(i) = 'g'; cipherV.at(i) = ')'; ++i;
    normalV.at(i) = 'h'; cipherV.at(i) = '-'; ++i;
    normalV.at(i) = 'i'; cipherV.at(i) = '#'; ++i;
    normalV.at(i) = 'j'; cipherV.at(i) = '_'; ++i;
    normalV.at(i) = 'k'; cipherV.at(i) = '='; ++i;
    normalV.at(i) = 'l'; cipherV.at(i) = '+'; ++i;
    normalV.at(i) = 'm'; cipherV.at(i) = '['; ++i;
    normalV.at(i) = 'n'; cipherV.at(i) = '{'; ++i;
    normalV.at(i) = 'o'; cipherV.at(i) = '$'; ++i;
    normalV.at(i) = 'p'; cipherV.at(i) = ']'; ++i;
    normalV.at(i) = 'q'; cipherV.at(i) = '}'; ++i;
    normalV.at(i) = 'r'; cipherV.at(i) = ';'; ++i;
    normalV.at(i) = 's'; cipherV.at(i) = ':'; ++i;
    normalV.at(i) = 't'; cipherV.at(i) = ','; ++i;
    normalV.at(i) = 'u'; cipherV.at(i) = '%'; ++i;
    normalV.at(i) = 'v'; cipherV.at(i) = '<'; ++i;
    normalV.at(i) = 'w'; cipherV.at(i) = '.'; ++i;
    normalV.at(i) = 'x'; cipherV.at(i) = '>'; ++i;
    normalV.at(i) = 'y'; cipherV.at(i) = '/'; ++i;
    normalV.at(i) = 'z'; cipherV.at(i) = '?'; ++i;

    // User inputs message
    do {
        cout << "Enter a secret message: ";
        getline(cin, toDec);
    } while (toDec.length() == 0);

    beenDec = toDec;

    //decodes user's message
    for (i = 0; i < setNum; ++i){
    if (toDec.at(0) == cipherV.at(i)) {
            beenDec.at(0) = normalV.at(i);
        }
    }

    //diplays decoded message
    cout << "Decrypted message: " << beenDec << endl;

    //command drive to stay open
    cin.get();
    cin.get();
    return 0;
}

May 28th, 2015

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
May 28th, 2015
...
May 28th, 2015
Jun 29th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer