Is anybody familiar with the caesar shift function? My encoding and decoding are putting out the same information, and I am not sure how to fix it. I am a beginner programmer and any help/guidance would be appreciated.
[code]
//Constant Declarations
const int W_WIDTH = 80; ///< Width of the terminal window
//Forward Declarations - Function Prototypes
///
/// Utility Function to read a value from an input stream ( any type with a operator>> defined ) - non-interactive
///
template<class T>
bool readValue( istream &in_stream, T &value_in);
///
/// Utility Function to read a value from an input stream - interactive
///
template<class T>
bool readValue( istream &in_stream, T &value_in, string message, int width=34 );
///
/// Print a horizontal line
///
void printHorizontalLine( ostream& outs, char line_char, int width );
///
/// Print a centered heading
///
void printHeading( string title, int width );
///
/// Print the stylized program/project heading
///
void printProjectHeading( ostream& outs, int width );
///
/// Apply the caesar cipher
///
char caesarShift( char to_shift, int shift_value);
///
/// Print the encode and decode selection menu
///
void printMenu();
///
/// Read the shift value from the keyboard
///
int readShiftValue();
///
/// Main Function
///
int main(){
fstream in_file; ///< Input File Stream
fstream out_file; ///< Output File Stream
string input_filename; ///< Input File Name
string output_filename; ///< Output File Name
string line;
string title;
///< String to store each line
int shift_value =0; ///< Shift Value for caesar Cipher
char choice = '\0'; ///< User menu selection
char current_char = '\0'; ///< Current character to be processed
//Print the program heading
printProjectHeading( cout, W_WIDTH);
// Read the input and output file names
readValue( cin, input_filename, "Read from which file? ");
readValue( cin, output_filename, "Write to which file? ");
//Read the Shift "Key" Value
shift_value = readShiftValue( );
//Display the Encode Decode Selection Menu
printMenu();
//Read the User Selection and convert to uppercase
readValue( cin, choice, "Select an Option: " );
choice = toupper( choice );
//Validate the user selection
//D - decode - reverse the shift direction
//E - encode - no addional logic
//other - error and quit
if( choice == 'D' ){
shift_value = -1 * ( shift_value );
}
if (choice !='D' && choice != 'E'){
shift_value = 0 * (shift_value);
if( choice == 'E'){ //error and program termination if wrong value entered.
shift_value = 0 * (shift_value);
}
cout << "ERROR! YOU HAVE ENTERED AN INVALID VALUE!"; // Error message if value entered >1, <25.
return 0;
}
//read each line of the file
//Read the line
while( !in_file.eof() ){ //loop to obtain each line of the input file.
getline( in_file, line );
//Iterate through each character in the line string
for( int i = 0; i < line.length(); i++){
current_char = line[i]; //Retrieve the i-th character from "line"
//Retrieve the i-th character from the string
//MODIFY the following line
//Hint: array subscripts - line[ some # ]
//Convert the line to uppercase
current_char = toupper( current_char );
//If the character is in the range A to Z, apply the caesar shift
//otherwise output the character unmodified
if( current_char >= 'A' && current_char <= 'Z' ){
out_file << caesarShift( current_char, shift_value );
}
else{
out_file << current_char;
}
}
//If the current line is not the last, output a newline character
// MODIFY - Do not output an extra newline at the end of the file
out_file << "\n";
}
//Close the input and output files
in_file.close(); //close the input and output files.
out_file.close();