h5.h
/* Date: October 8, 2020
File: hw5.h
Purpose: Function prototypes used for simulating the
processing of a message through a simplified
Enigma machine containing "interchangeable"
rotors.
*/
#ifndef HW5_H
#define HW5_H
#include <iostream>
using namespace std;
// ******************************************************
// Constants
const short NUM_ROTORS = 5; // # possible rotors
// to choose from
const char END_OF_MESSAGE_CHAR = '.'; // signals end of msg
const char WORD_DELIMITER = '_'; // delimits 2 words in
// msg
const short NUM_LETTERS = 26; // # letters in
// alphabet
const short ASCII_A = 65; // ASCII value of 'A'
const short ASCII_Z = 90; // ASCII value of 'Z'
// ******************************************************
// Function prototypes
// Display a greeting to the user.
// Preconditions: None
// Postconditions: A message has been output to the screen.
void outputGreeting();
// Display a sign-off message to the user.
// Preconditions: None
// Postconditions: A message has been output to the screen.
void outputSignOff();
// Prompt for and get input from the user, validating
// the input to make sure it is within the specified range.
// Preconditions: Parameter 'prompt' contains a string
// describing what information the user is to enter.
// Parameters 'minVal' and 'maxVal' constitute the valid
// range of values for user input.
// Postconditions: A value within the specified range will be
// returned.
short getShortInput(const string prompt,
const short minVal, const short maxVal);
// Prompt for and get a single char input from the user.
// Valid chars are uppercase letters, period, and underscore.
// Preconditions: None.
// Postconditions: An uppercase letter, period, or underscore
// is returned.
char getCharInput( );
// Prompt for and get user's selections for the left, middle,
// and right rotors. Note: No rotor can be used more than once.
// Preconditions: None.
// Postconditions: Pass-by-reference parameters 'leftRotor',
// 'middleRotor', and 'rightRotor' will contain the values
// of the selected rotor numbers.
void getRotorSelections(short& leftRotor, short& middleRotor,
short& rightRotor);
// Translate a character ch into another character using
// the function ((ch + 3) % 26) + 65 after having shifted
// ch a certain number of positions from the last ch
// processed by this function.
// Preconditions: Parameter 'ch' should be an uppercase
// letter.
// Postconditions: An uppercase letter is returned.
char rotor1(const char ch);
// Translate a character ch into another character using
// the function ((ch + 17) % 26) + 65 after having shifted
// ch a certain number of positions from the last ch
// processed by this function.
// Preconditions: Parameter 'ch' should be an uppercase
// letter.
// Postconditions: An uppercase letter is returned.
char rotor2(const char ch);
// Translate a character ch into another character using
// a specific 1-1 mapping after having shifted ch a certain
// number of positions from the last ch processed by this
// function.
// Preconditions: Parameter 'ch' should be an uppercase
// letter.
// Postconditions: An uppercase letter is returned.
char rotor3(const char ch);
// Translate a character ch into another character. If ch's
// ASCII value is odd, translate it to the next ASCII character;
// otherwise, translate ch to the previous ASCII character.
// This is done after having shifted ch a certain
// number of positions from the last ch processed by this
// function.
// Preconditions: Parameter 'ch' should be an uppercase
// letter.
// Postconditions: An uppercase letter is returned.
char rotor4(const char ch);
// Translate a character ch into the next uppercase letter
// character whose ASCII value is a multiple of 3. This is
// done after having shifted ch a certain number of positions
// from the last ch processed by this function.
// Preconditions: Parameter 'ch' should be an uppercase
// letter.
// Postconditions: An uppercase letter is returned.
char rotor5(const char ch);
// Call the function associated with the specified rotor
// to translate the given character.
// Preconditions: Parameter 'whichRotor' should be a
// valid rotor number and parameter 'encryptedChar' should
// be an uppercase letter.
// Postconditions: An uppercase letter is returned.
char translateChar(const short whichRotor,
const char encryptedChar);
// Determine whether or not a specified value is a multiple
// of 3.
// Preconditions: Parameter 'val' should have a value.
// Postconditions: Returns true if 'val' is a multiple of 3;
// otherwise, returns false.
bool isMultipleOf3(const short val);
// Translate an uppercase alphabetic character to another
// character based on its position from a previous character.
// Preconditions: Parameters 'prevChar' and 'newChar' should
// be uppercase alphabeteric characters.
// Postconditions: Returns an uppercase alphabetic character.
char shiftChar(const char prevChar, const char newChar);
#endif