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:
CaesarCipherSpi
Alphabet
Constructor Summary |
CaesarKey()
Default constructor required. |
CaesarKey(int shift)
Creates the CaesarKey with the specified shift. |
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" for example). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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.
CaesarKey
public CaesarKey()
- Default constructor required.
CaesarKey
public CaesarKey(int shift)
throws java.lang.Exception
- Creates the CaesarKey with the specified shift. The default alphabet is set to "az".
- Parameters:
shift
- is a positive integer, i.e. "5" which would be stored in the
instance variables shift as an integer and keyword as a String.
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" 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