Question
Help with this substitution program, line 3 of the output is different than it should be and I can't find the reaso why. Here's the
Help with this substitution program, line 3 of the output is different than it should be and I can't find the reaso why. Here's the code, the input file, and the output file.
#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 smile = new CipherCheshire(); smile->cipher_alpha = "zyxwvutsrqponmlkjihgfedcba"; }
/* This constructor initiates the object with a input cipher key */ Cipher::Cipher(string cipher_alpha) { // TODO: Implement this constructor smile - new CipherCheshire(); if (is_valid_alpha(cipher_alpha)) { smile->cipher_alpha = cipher_alpha; } else { cout
/* Destructor */ Cipher::~Cipher() { // TODO: Implement this constructor delete(smile); }
/* This member function encrypts the input text using the intialized cipher key */ string Cipher::encrypt(string raw) { cout cipher_alpha, ch) if (ch >= 65 && ch
cout
return retStr; }
/* This member function decrypts the input text using the intialized cipher key */ string Cipher::decrypt(string enc) { string retStr = ""; char ch, tmp; int pos; int i; int size = enc.length(); cout cipher_alpha, ch); if (ch >= 65 && ch
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; } INPUT:
EXPECTED OUTPUT:
CURRENT OUTPUT:
zyxwvutsrqponmlkj ihgfedcba Sometimes it is the people no one can imagine anything of who do the things no one can imagine Hlnvgrnvh rg rh gsv kvlkov ml lmv Xzm rnztrmv zmbgsrmt lu dsl wl gsv gsrmth ml lmv Xzm rnztrmv 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 Hlnvgrnvh rg rh gsv kvlkov ml lmv xzm rnztrmv zmbgsrmt lu dsl wl gsv gsrmth ml lmv xzm rnztrmv Sometimes it is the people no one can imagine anything of who do the things no one can imagine Hlnvgrnvh rg rh gsv kvlkov ml lmv Xzm rnztrmv zmbgsrmt lu dsl wl gsv gsrmth ml lmv Xzm rnztrmv Sometimes it is the people no one can imagine anything of who do the things no one can imagineStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started