Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

One of the most important tasks modern computers perform is cryptography. Strong

ID: 3848193 • Letter: O

Question

One of the most important tasks modern computers perform is cryptography. Strong encryption lets us keep our network passwords private, our commercial and financial transactions on the Internet secure, and our personal information safe from prying eyes. Computers are well-suited to the complex, repetitive mathematical operations that make modern cryptosystems effective. In fact, the immediate ancestors of modern computers were invented by the Allies in World War II to crack the codes used by the Axis powers. Those codes, like the German Enigma, were implemented with mechanical encryption systems, like gears and rotors; they were quickly broken by the new generation of digital electronic machines. But methods of encrypting and obscuring text have been in use for thousands of years. One of the oldest is called the Caesar cipher, after Julius Caesar, who used it to communicate with his political and military allies. The cipher is very simple: choose a secret (integer) number (called a key). Write out your message in all capital letters, with no spaces or punctuation. Then, shift" each character through the alphabet by the same number of spots as your secret key (rightward if the key is positive, leftward if the key is negative). To decrypt the message, shift each character leftward by the key number. If, while going in either direction, you reach the end of the alphabet, wrap around and continue at the other end So, for example, if we were using the Caesar cipher a key of 10, we would change the letters of the alphabet like so: Plaintext: A B C DE F G H I J K L M N 0 P Q R ST U V W X Y Z Cipher text: K L M N 0 P Q R S T U V W X Y Z ABC D E F G H I J (In cryptography, plaintext is the term for the original message; ciphertext is the term for the encrypted message.) By using this cipher, the plaintext message HAILCAESAR would become RKSVMKOCKB once we had shifted each character right by 10 places This mechanism shifting the letters and wrapping around the ends of the list is analogous to the mathematical operation modulo division, which divides one integer by another and returns the remainder. We can use the modulo operation to implement the Caesar cipher by imagining that each letter is actually a number, starting at 1 for A and ending with 26 for Z. Then, the operation can be implemented in MATLAB by using the command on two variables containing scalar integers: plaintext R 18 'R' is the eighteenth Letter of the alphabet key 10 cipher R modCplaintextR key, 26) This code applies the Caesar cipher to the letter R to get that Bis the corresponding encoded letter (since 18+10 28 and the remainder from doing 28+26 is 2). In other words, the modulo division by 26 takes care of wrapping the sum of the letter and shift (see the information about the function for mod an important note about mapping results of the function to the 26 letters of the alphabet).

Explanation / Answer

#include "BSTree.h"
template <typename DataType, category KeyType>
BSTree<DataType, KeyType>::BSTreeNode::BSTreeNode ( const DataType &nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr )

template < typename DataType, category KeyType >
BSTree<DataType, KeyType>::BSTree ()

template < typename DataType, category KeyType >
BSTree<DataType, KeyType>::BSTree ( const BSTree<DataType,KeyType>& alternative )

template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>:: copyTree(const BSTree<DataType, KeyType> &otherTree)

template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>:: copyTreeHelper(BSTreeNode *&p, const BSTreeNode *otherPtr)

}
template < typename DataType, category KeyType >
BSTree<DataType, KeyType>& BSTree<DataType, KeyType>:: operator= ( const BSTree<DataType,KeyType>& alternative )

template < typename DataType, category KeyType >
BSTree<DataType, KeyType>::~BSTree ()

template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>::insert ( const DataType& newDataItem )

template < typename DataType, category KeyType >
bool BSTree<DataType, KeyType>::retrieve ( const KeyType& searchKey, DataType& searchDataItem ) const
come back false;
}
template < typename DataType, category KeyType >
bool BSTree<DataType, KeyType>::remove ( const KeyType& deleteKey )
come back false;
}
template < typename DataType, category KeyType >
bool BSTree<DataType, KeyType>::removeHelper(BSTreeNode *&p, const KeyType& deleteKey)

template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>::writeKeys () const

template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>::writeLTHelper(BSTreeNode *p, const KeyType& searchKey) const

template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>::clear ()

template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>::clearHelper(BSTreeNode *p)

template < typename DataType, category KeyType >
bool BSTree<DataType, KeyType>::isEmpty () const
come back false;
}
template < typename DataType, category KeyType >
int BSTree<DataType, KeyType>::getHeight () const

template < typename DataType, category KeyType >
int BSTree<DataType, KeyType>::getHeightHelper(BSTreeNode *p) const


template < typename DataType, category KeyType >
int BSTree<DataType, KeyType>::getCount () const

template < typename DataType, category KeyType >
int BSTree<DataType, KeyType>::getCountHelper(BSTreeNode *p) const


template < typename DataType, category KeyType >
void BSTree<DataType, KeyType>::writeLessThan ( const KeyType& searchKey ) const


#include "show9.cpp"
/////////////////////////////////////////////////////////////////////////////////////////
Class declarations for the joined implementation of the Binary
// Search Tree ADT -- together with the algorithmic helpers of the
// public member functions
//
//--------------------------------------------------------------------
#ifndef BSTREE_H
#define BSTREE_H
#include <stdexcept>
#include <iostream>
using namespace std;
template < typename DataType, category KeyType > // DataType : tree information item
class BSTree // KeyType : key field
builder
BSTree(); // Default creator
BSTree(const BSTree<DataType, KeyType>& other); // Copy creator
BSTree& operator= (const BSTree<DataType, KeyType>& other);
// full assignment operator
// Destructor
~BSTree();
// Binary search tree manipulation operations
void insert(const DataType& newDataItem); // Insert information item
bool retrieve(const KeyType& searchKey, DataType& searchDataItem) const;
// Retrieve information item
bool remove(const KeyType& deleteKey); // take away information item
void writeKeys() const; // Output keys
void clear(); // Clear tree
// Binary search tree standing operations
bool isEmpty() const; // Tree is empty
// !! isFull() has been retired. Not terribly helpful in a very joined structure.
// Output the tree structure -- utilized in testing/debugging
void showStructure() const;
// In-lab operations
int getHeight() const; // Height of tree
int getCount() const; // variety of nodes in tree
void writeLessThan(const KeyType& searchKey) const; // Output keys < searchKey
protected:
category BSTreeNode // Inner category: helper for the BSTree class
{
public:
// creator
BSTreeNode(const DataType &nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr);
// information members
DataType informationItem; // Binary search tree data item
BSTreeNode *left, // Pointer to the left kid
*right; // Pointer to the correct kid
};
// algorithmic helpers for the general public member functions -- insert
// prototypes of those functions here.
void insertHelper(BSTreeNode *&p, const DataType &newDataItem);
bool retrieveHelper(BSTreeNode *p, const KeyType& searchKey, DataType &searchDataItem) const;
bool removeHelper(BSTreeNode *&p, const KeyType& deleteKey);
// cutRightmose utilized in one implementation of take away.
void cutRightmost(BSTreeNode *&r, BSTreeNode *&delPtr);
void writeKeysHelper(BSTreeNode *p) const;
void clearHelper(BSTreeNode *p);
void showHelper(BSTreeNode *p, int level) const;
int getHeightHelper(BSTreeNode *p) const;
int getCountHelper(BSTreeNode *p) const;
void writeLTHelper(BSTreeNode *p, const KeyType& searchKey) const;
void copyTree(const BSTree<DataType, KeyType> &otherTree);
void copyTreeHelper(BSTreeNode *&p, const BSTreeNode *otherPtr);
// information member
BSTreeNode *root; // Pointer to the basis node
};
#endif // outline BSTREE_H