/**
 * Class that implements a substitution cipher for encoding/decoding messages.
 *   @author Dave Reed
 *   @version 11/13/09
 */
public class Cipher {
    private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
    private String keyString;

    /**
     * Constructs the default substitution cipher, the Caesar cipher.
     */
    public Cipher() {
        this.keyString = "defghijklmnopqrstuvwxyzabc";
    }

    /**
     * Constructs a substitution cipher using the specified key string.
     *   @param key the string that is used to map the letters of the alphabet.
     */
    public Cipher(String key) {
        this.keyString = key;
    }
	
    /**
     * Encodes a single character using the substitution cipher.
     *   @param ch the character to be encoded
     *   @return the encoded character
     */
    public char encode(char ch) {
        int index = Cipher.ALPHABET.indexOf(ch);
        return this.keyString.charAt(index);
    }
	
    /**
     * Decodes a single character using the substitution cipher.
     *   @param ch the character to be decoded
     *   @return the decoded character
     */
    public char decode(char ch) {
        int index = this.keyString.indexOf(ch);
        return Cipher.ALPHABET.charAt(index);
    }
	
    /**
     * Encodes an entire string using the substitution cipher.
     *   @param text the string to be encoded
     *   @return the encoded string
     */
    public String encode(String text) {
        return "???";
    }
    
    /**
     * Decodes an entire string using the substitution cipher.
     *   @param code the string to be decoded
     *   @return the decoded string
     */
    public String decode(String code) {
        return "???";
    }
}
