Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main(int argc, const char * argv[]) {
- const int cipherLength = 26;
- vector<char> normalV(26);
- vector<char> cipherV(26);
- string toDec = "";
- string beenDec = "";
- int i = 0;
- int k = 0;
- //cipher character association in vector
- normalV.at(i) ='a'; cipherV.at(i) = '!';
- normalV.at(i) ='b'; cipherV.at(i) = '^';
- normalV.at(i) ='c'; cipherV.at(i) = '&';
- normalV.at(i) ='d'; cipherV.at(i) = '*';
- normalV.at(i) ='e'; cipherV.at(i) = '@';
- normalV.at(i) ='f'; cipherV.at(i) = '(';
- normalV.at(i) ='g'; cipherV.at(i) = ')';
- normalV.at(i) ='h'; cipherV.at(i) = '-';
- normalV.at(i) ='i'; cipherV.at(i) = '#';
- normalV.at(i) ='j'; cipherV.at(i) = '_';
- normalV.at(i) ='k'; cipherV.at(i) = '=';
- normalV.at(i) ='l'; cipherV.at(i) = '+';
- normalV.at(i) ='m'; cipherV.at(i) = '[';
- normalV.at(i) ='n'; cipherV.at(i) = '{';
- normalV.at(i) ='o'; cipherV.at(i) = '$';
- normalV.at(i) ='p'; cipherV.at(i) = ']';
- normalV.at(i) ='q'; cipherV.at(i) = '}';
- normalV.at(i) ='r'; cipherV.at(i) = ';';
- normalV.at(i) ='s'; cipherV.at(i) = ':';
- normalV.at(i) ='t'; cipherV.at(i) = ',';
- normalV.at(i) ='u'; cipherV.at(i) = '%';
- normalV.at(i) ='v'; cipherV.at(i) = '<';
- normalV.at(i) ='w'; cipherV.at(i) = '.';
- normalV.at(i) ='x'; cipherV.at(i) = '>';
- normalV.at(i) ='y'; cipherV.at(i) = '/';
- normalV.at(i) ='z'; cipherV.at(i) = '?';
- // Get secret message input
- do {
- cout << "Enter a secret message: ";
- getline(cin, toDec);
- } while (toDec.length() == 0);
- beenDec = toDec;
- //need to create a loop to go through vector and replace all instances of cipher
- //need to loop through input string and compare each char against vector
- // Decrypt secret message
- //input string
- for (i = 0; i < toDec.length(); i++)
- {
- //character comparison
- for(k = 0; k < cipherLength; ++k)
- {
- if (toDec.at(i) == cipherV.at(k))
- {
- beenDec.at(i) = normalV.at(k);
- }
- }
- }
- cout << "Decrypted message: " << beenDec << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement