hw6_main.cpp

/* Programmer: Jennifer Leopold Date: October 8, 2015

File: hw6_main.cpp

Purpose: Simulate processing of a message through a

simplified Enigma machine containing 3 "inter-

changeable" rotors.

To compile: fg++ hw6_main.cpp hw6_functs.cpp -o hw6

To execute: ./hw6

*/

#include <iostream>

#include "hw6_functs.h"

using namespace std;

int main()

{

short leftRotor, middleRotor, // order that rotors

rightRotor; // should be applied

short whichRotor; // rotor currently

// being processed

char encryptedChar; // encrypted char (user input)

// Greet user

outputGreeting();

// Get input for order that the 3 rotors should be applied

getRotorSelections(leftRotor, middleRotor, rightRotor);

// Get each char in message (until END_OF_MESSAGE_CHAR input)

// and output the decrypted char

do

{

encryptedChar = getCharInput();

if (encryptedChar != END_OF_MESSAGE_CHAR)

{

if (encryptedChar != WORD_DELIMITER)

{

// Note: The escape sequence \033[F will go up

// to the beginning of the previous line on the

// terminal

cout << "\033[F" << encryptedChar << " -> ";

// Process the char through each of the 3 rotors

for (short rotorNum = 1; rotorNum <= 3; rotorNum++)

{

// Determine which rotor we're working on

switch (rotorNum)

{

case 1 : whichRotor = leftRotor; break;

case 2 : whichRotor = middleRotor; break;

case 3 : whichRotor = rightRotor; break;

}

// Do the processing for whichRotor

encryptedChar = translateChar(whichRotor,

encryptedChar);

}

cout << encryptedChar << endl; // Now decrypted

}

else cout << WORD_DELIMITER << endl;

}

} while (encryptedChar != END_OF_MESSAGE_CHAR);

// Sign-off

outputSignOff();

return 0;

}