hcrypto.engines
Class CaesarKey

java.lang.Object
  |
  +--hcrypto.cipher.HistoricalKey
        |
        +--hcrypto.engines.CaesarKey

public class CaesarKey
extends HistoricalKey

This class represents a key for a Caesar (shift) cipher. The key is entirely represented by an integer, shift, which specifies by how many characters each letter of the plaintext is supposed to be shifted to the right in the alphabet. For example, with a shift of 3, the letter 'A' would become 'D' and the digit '1' would become '4'.

For this implementation of Caesar cipher any of the alphabet ranges can be used and any nonnegative shift value can be specified. If the shift exceeds the range of characters in the alphabet -- e.g., if the shift is 100 and the alphabet is 'a'..'z', then the shift is scaled modulo 26. Negative shift values are rejected, resulting in an exception.

See also:


CaesarEngine
Alphabet


Field Summary
static java.lang.String DEFAULT_KEY_DESCRIPTOR_PROMPT_STRING
          A description for a Caesar Key.
static java.lang.String DEFAULT_KEYWORD_STRING
          A default key value.
 
Fields inherited from class hcrypto.cipher.HistoricalKey
alphabet, blocksize, ciphAlphabet, cipherAlphabet, keyDescriptorPrompt, keyspec, keyword, plainAlphabet
 
Constructor Summary
CaesarKey()
           
 
Method Summary
 java.lang.String getAlgorithm()
          Returns the algorithm name "Caesar".
 int getShift()
          Returns shift value.
 void init(java.lang.String keyspec)
          Initializes the CaesarKey with the specified keyspec (which takes the form "4/az" or "4/az/AZ" for example).
 
Methods inherited from class hcrypto.cipher.HistoricalKey
getAlphabet, getBlocksize, getCiphAlphabet, getCTAlphabet, getInstance, getKeyDescriptorPrompt, getKeyword, getPlainAlphabet, initAlphabets, initKey, printAlphabets, removeDuplicateChars
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_KEY_DESCRIPTOR_PROMPT_STRING

public static final java.lang.String DEFAULT_KEY_DESCRIPTOR_PROMPT_STRING
A description for a Caesar Key.

DEFAULT_KEYWORD_STRING

public static final java.lang.String DEFAULT_KEYWORD_STRING
A default key value.
Constructor Detail

CaesarKey

public CaesarKey()
Method Detail

init

public void init(java.lang.String keyspec)
          throws java.lang.Exception
Initializes the CaesarKey with the specified keyspec (which takes the form "4/az" or "4/az/AZ" for example).
Overrides:
init in class HistoricalKey
Parameters:
keySpec - takes the form "integer/alphabet", i.e. "5/azAZ09" which would be mapped into the instance variables shift as an integer with the value of 5, keyword as a String with the value of "5", and alphabet as a String with the value "azAZ09".

getShift

public int getShift()
Returns shift value.

getAlgorithm

public java.lang.String getAlgorithm()
Returns the algorithm name "Caesar".
Overrides:
getAlgorithm in class HistoricalKey