Given two char arrays, containing the alphabet, where one is the random permutation of the other, write a method that can utilize these arrays to encrypt and decrypt a given text via a simple substitution cipher. // Switching the vectors, a and b, will decrypt an encrypted text void Cipher(string &text, vector<char> a, vector<char> b) { if (text.empty() || a.size() != b.size() || a.empty()) return; hash_map<char, char> cipher_map; for (int i = 0; i < a.size(); i++) cipher_map[a[i]] = b[i]; for (int i = 0; i < text.size(); i++) { char c = cipher_map[text[i]]; if ('\0' != c) text[i] = c; } } |