plugins
Class CaesarKey

java.lang.Object
  extended by hcrypto.cipher.HistoricalKey
      extended by plugins.CaesarKey

public class CaesarKey
extends HistoricalKey

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.
 
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).
 void init(java.lang.String keyword, Alphabet alpha1, Alphabet alpha2)
          Initializes the CaesarKey given a keyword and one or more alphabets.
 
Methods inherited from class hcrypto.cipher.HistoricalKey
getAlphabet, getBlocksize, getCipherKey, getCTAlphabet, getInstance, getKeyDescriptorPrompt, getKeyword, getPlainKey, initKey, initKey, invertKey, printAlphabets, removeDuplicateChars
 
Methods inherited from class java.lang.Object
equals, 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.

See Also:
Constant Field Values

DEFAULT_KEYWORD_STRING

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

See Also:
Constant Field Values
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).

Specified by:
init in class HistoricalKey
Parameters:
keySpec - takes the form "integer/alphabet", i.e. "5/az+AZ+09" 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 "az+AZ+09".
Throws:
java.lang.Exception

init

public void init(java.lang.String keyword,
                 Alphabet alpha1,
                 Alphabet alpha2)
          throws java.lang.Exception
Initializes the CaesarKey given a keyword and one or more alphabets.

Specified by:
init in class HistoricalKey
Parameters:
keyword - -- a string version of the keyword
alpha1, - alpha2 -- Alphabets for plain/ciphertext respectively. May be identical.
Throws:
java.lang.Exception

getShift

public int getShift()
Returns shift value.


getAlgorithm

public java.lang.String getAlgorithm()
Returns the algorithm name "Caesar".

Specified by:
getAlgorithm in class HistoricalKey