/*
 * 2004 Utah High School Programming Contest, University of Utah
 * Take-Home Problem
 *
 * RotationCipher.hpp
 *
 * This file contains the definition of the RotationCipher class.
 */

#ifndef ROTATIONCIPHER_HPP
#define ROTATIONCIPHER_HPP

#include "Cipher.hpp"

#include <string>

using namespace std;

/**
 * A RotationCipher implements a particular letter rotation algorithm.  For
 * example, a RotationCipher might rotate every letter forward by one position,
 * mapping 'A' to 'B', 'B' to 'C', ..., and 'Z' to 'A'.  The rotation wraps
 * around at the end of the alphabet.  The distance of the rotation is
 * determined when the RotationCipher object is created.  There are 26 possible
 * rotation algorithms (including the shift-by-zero algorithm).
 *
 * RotationCipher is a subclass of the (abstract) Cipher class.
 * RotationCiphers are created by the Search class.
 */
class RotationCipher : public Cipher {
private:
    /**
     * The array that describes the translations of lowercase letters.  Array
     * index 0 corresponds to 'a', 1 to 'b', and so on.  The value of an array
     * element is the translation of the letter that corresponds to that
     * element's index.  For example, the value of `lowercase_map[0]' is the
     * translation of `a'.
     */
    char lowercase_map[26];
    
    /**
     * The array that describes the translations of uppercase letters.  Array
     * index 0 corresponds to 'A', 1 to 'B', and so on.  The value of an array
     * element is the translation of the letter that corresponds to that
     * element's index.  For example, the value of `uppercase_map[0]' is the
     * translation of `A'.
     */
    char uppercase_map[26];
    
public:
    /**
     * Construct a RotationCipher object to implement a particular letter
     * rotation algorithm.  The argument to this method represents the
     * "distance" of the rotation for decryption.  For example, a distance of
     * one means that 'A' decrypts to 'B', 'B' to 'C', ..., and 'Z' decrypts to
     * 'A'.  (The rotation wraps around at the end of the alphabet.)  Letter
     * case is preserved.  Only upper- and lowercase letters are translated;
     * all other characters "decrypt" to themselves.
     *
     * @param decipher_distance    the "distance" of the letter rotation
     */
    RotationCipher(int decipher_distance);
    
    /**
     * Destroy a RotationCipher object.
     */
    virtual ~RotationCipher();
    
    /**
     * Modify the given string by applying this RotationCipher's algorithm to
     * it.  This may or may not actually decrypt the string into English text;
     * the caller must decide if this RotationCipher's algorithm actually
     * "worked."
     *
     * @param cryptogram    the string to be modified
     */
    virtual void decipher(string& cryptogram) const;
};

#endif // ROTATIONCIPHER_HPP

// End of file.

