Question: Please help reviewing the following code for caesar cipher (ccipher.h and ccipher.cc) which is giving incorrect output. It must inherit from susbtitution cipher (cipher.cc) which

Please help reviewing the following code for caesar cipher (ccipher.h and ccipher.cc) which is giving incorrect output. It must inherit from susbtitution cipher (cipher.cc) which I include below as well as the wrong output and the expected output.

There are no typos, I've made sure of it so that is not reason.

SUBSTITUTION CIPHER

cipher.cc

#include "cipher.h"

/* Cheshire smile implementation. It only contains the cipher alphabet */ struct Cipher::CipherCheshire { string cipher_alpha; };

/* This function checks the cipher alphabet to make sure it's valid */ bool is_valid_alpha(string alpha);

// ------------------------------------------------------- // Cipher implementation /* Default constructor This will actually not encrypt the input text because it's using the unscrambled alphabet */ Cipher::Cipher() { // TODO: Implement this default constructor this->smile = new CipherCheshire(); this->smile->cipher_alpha = "abcdefghijklmnopqrstuvwxyz"; }

/* This constructor initiates the object with a input cipher key */ Cipher::Cipher(string cipher_alpha) { // TODO: Implement this constructor if (is_valid_alpha(cipher_alpha)) { this->smile - new CipherCheshire(); this->smile->cipher_alpha = cipher_alpha; } else { cout

/* Destructor */ Cipher::~Cipher() { // TODO: Implement this constructor delete this->smile; }

/* This member function encrypts the input text using the intialized cipher key */ string Cipher::encrypt(string raw) { cout

for (int i = 0; i cipher_alpha, LOWER_CASE(raw[i])); if (isupper(raw[i])) { retStr += UPPER_CASE(alph[pos]); } else { retStr += alph[pos]; } } }

cout

return retStr; }

/* This member function decrypts the input text using the intialized cipher key */ string Cipher::decrypt(string enc) { string retStr; int length = enc.length(); int pos; string alph = "abcdefghijklmnopqrstuvwxyz";

for (int i = 0; i cipher_alpha, LOWER_CASE(enc[i])); if (isupper(enc[i])) { retStr += UPPER_CASE(alph[pos]); } else { retStr += alph[pos]; } } }

cout

return retStr;

} // -------------------------------------------------------

// Helper functions /* Find the character c's position in the cipher alphabet/key */ unsigned int find_pos(string alpha, char c) { unsigned int pos = 0; int i; int size = alpha.length();

// TODO: You will likely need this function. Finish it. char ch = tolower(c); for (i = 0; i

return pos; }

/* Make sure the cipher alphabet is valid - a) it must contain every letter in the alphabet b) it must contain only one of each letter c) it must be all lower case letters ALL of the above conditions must be met for the text to be a valid cipher alphabet. */ bool is_valid_alpha(string alpha) { bool is_valid = true; if(alpha.size() != ALPHABET_SIZE) { is_valid = false; } else { unsigned int letter_exists[ALPHABET_SIZE]; for(unsigned int i = 0; i = 'a') && (c

return is_valid; }

CAESAR CIPHER:

ccipher.h

Please help reviewing the following code for caesar cipher (ccipher.h and ccipher.cc)

ccipher.cc

which is giving incorrect output. It must inherit from susbtitution cipher (cipher.cc)

INPUT TEXT:

which I include below as well as the wrong output and the

EXPECTED OUTPUT:

expected output. There are no typos, I've made sure of it so

MY WRONG OUTPUT:

that is not reason. SUBSTITUTION CIPHER cipher.cc #include "cipher.h" /* Cheshire smile

30 Sometimes it is the people no one can imagine anything of who do the things no one can imagine Wsqixmqiw mx mw xli tistpi rs sri ger mqekmri ercxlmrk sj als hs xli xlmrkw rs sri ger mqekmri Sometimes it is the people no one can imagine anything of who do the things no one can imagine Sometimes it is the people no one can imagine anything of who do the things no one can imagine Sometimes it is the people no one can imagine anything of who do the things no one can imagine Okiapeiao ep eo pda laklha jk kja ywj eiwceja wjupdejc kb sdk zk pda pdejco jk kja ywj eiwceja Kgewlaewk al ak lzw hwghdw fg gfw usf aesyafw sfqlzafy gx ozg vg lzw lzafyk fg gfw usf aesyafw Sometimes it is the people no one can imagine anything of who do the things no one can imagine Sometimes it is the people no one can imagine anything of who do the things no one can imagine

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!