// Coder.h - contains a single wheel of an Enigma machine // includes reading of keyword, offset and // letter, if any, to remove from wheel #ifndef CODER_CLASS #define CODER_CLASS #include #include "SuperTnode.h" class Coder { SuperTnode *plainFront; // points to plaintext dl SuperTnode *cipherFront; // points to cipher sll std::string keyword; // keyword int offset; // where to begin aligning plaintext with cipher public: // default constructor // initializes front Coder(); // copy constructor // makes a copy of "other" // calls copy() Coder(const Coder & other); // destructor // calls makeEmpty() ~Coder(); // explicitly defined assignment operator Coder & operator=(const Coder &); // accessor for plain front // returns pointer to plaintext front SuperTnode * getPlainFront() const; // accessor for cipher front // returns pointer to cipher front SuperTnode * getCipherFront() const; // mutator for plainFront // sets plainFront to ptr void setPlainFront(SuperTnode * ptr); // accessor for keyword // returns the keyword std::string getKeyword() const; // mutator for keyword // changes keyword to k void setKeyword(std::string k); // accessor for offset // returns the offset int getOffset() const; // mutator for offset // changes offset to p void setOffset(int p); // reads keyword (until number is detected) // reads offset (1 or 2 digits) void reader(); // strips duplicate letters out of keyword // converts all alphabetics to lowercase void stripKeyword(); // deletes all nodes in the list // THIS FUNCTION MUST BE RECURSIVE void makeEmpty(SuperTnode *); // finds the cipher letter x in the dll // returns true if letter is found // else returns false // THIS FUNCTION MUST BE RECURSIVE bool findCipher(const char x); // finds the plaintext letter x in the dll // returns true if found, else returns false // THIS FUNCTION MUST BE RECURSIVE bool findPlaintext(const char x); // locates plaintext letter x in dll // curr is pointing to SuperTnode containing x bool findPlaintext(const char x, SuperTnode *& curr); // finds plaintext letter that corresponds // to cipher letter x // curr points to SuperTnode containing plaintext corresponding to x bool findPlaintextForCipher(char x, SuperTnode *&curr); // function inserts plaintext x into dll void insert(const char x); // prints the word "plaintext:" // prints entire plaintext alphabet // alphabets are aligned // each letter is followed by one blank space void printPlain() const; // prints the word " cipher:" // prints entire cipher alphabet // alphabets are aligned void printCipher() const; // returns true if list is empty, else returns false bool isEmpty() const; // deletes the supertnode containing plaintext character x void erase(char x); // builds plaintext beginning with letter // at "offset" in 1st supertnode in dll void buildWheel(); // builds cipher from stripped keyword // followed by remainder of alphabet // this is accomplished AFTER Wheel is built // and all plaintext letters are in it // also hooks up cipherRight pointers to make // cipher linked list circular void addCipherThread(); private: // initializes the data members of this class void init(); // deep copy used in copy constructor and assignment operator void copy(const Coder &); // links cipher alphabet into circular, singly linked list void linkCipher(); // YOU MAY INCLUDE OTHER PRIVATE FUNCTIONS HERE // YOU MAY USE HELPER FUNCTIONS FOR RECURSION }; #endif // CODER_CLASS