|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--hcrypto.cipher.HistoricalKey
This abstract class provides a partial implementation of the HistoricalKey interface by providing default implementations of the getKeyword(), getAlphabet(), and getBlocksize() methods.
The HistoricalKey() constructor should be invoked by the subclass. It extracts the keyspec, which provides algorithm-specific data as well as a specification of the Alphabet used by the particular key. These are stored in instance variables.
The key specification is comprised of two parts: keydata/alphabetspec, separated by a forward slash "/". The keydata provides material that used to construct an algorithm-specific key. Here are some examples.
Algorithm | Keydata | AlphabetSpec |
---|---|---|
Caesar | shift | azAZ09 |
Substitution | keyword | printable |
Affine | a,b | az |
Here are some examples of key instantiations:
CaesarKey key = new CaesarKey("55/printable"); SubstitutionKey sKey = new SubstitutionKey("76TrombonesLEDTHEPARADE/azAZ09"); AffineKey aKey = new AffineKey("3,3/azAZ09");
Field Summary | |
protected Alphabet |
alphabet
This instance variable stores a reference to the particular plaintext characters for which this cipher is defined. |
protected int |
blocksize
Stores the blocksize. |
protected char[] |
ciphAlphabet
The ciphertext alphabet represented as a contiguous array of char. |
protected Alphabet |
cipherAlphabet
This instance variable stores a reference to the particular ciphertext characters for which this cipher is defined. |
protected java.lang.String |
keyDescriptorPrompt
Stores a prompt that can be used by the interface to describes the type of key that would be used for a particular cipher. |
protected java.lang.String |
keyspec
A keyspec takes the form keydata/plainalphabetspec/cipheralphabetspec, where plainalphabetspec is a sepcification for the plaintext alphabet, and cipheralphabetspec is a specification for the ciphertext alphabet. |
protected java.lang.String |
keyword
Many historical ciphers use a keyword as part (or all) of the key. |
protected char[] |
plainAlphabet
The plaintext alphabet represented as a contiguous array of char. |
Constructor Summary | |
HistoricalKey()
|
Method Summary | |
abstract java.lang.String |
getAlgorithm()
This abstract method should be implemented in the algorithm-specific subclass. |
Alphabet |
getAlphabet()
Returns a reference to this key's alphabet. |
int |
getBlocksize()
Returns this cipher's blocksize. |
char[] |
getCiphAlphabet()
Returns the cipher alphabet. |
Alphabet |
getCTAlphabet()
Returns a reference to this key's cipherAlphabet. |
static HistoricalKey |
getInstance(java.lang.String algorithm,
java.lang.String provider)
searches for the provider named in the second parameter for an implementation of the algorithm named in its first parameter. |
java.lang.String |
getKeyDescriptorPrompt()
Returns an interface prompt describing the key |
java.lang.String |
getKeyword()
Returns the keyword for this key. |
char[] |
getPlainAlphabet()
Returns the plaintext alphabet. |
abstract void |
init(java.lang.String keyspec)
This abstract method should be implemented in the algorithm-specific subclass. |
protected void |
initAlphabets()
This method constructs char arrays consisting of the characters in the plaintext and ciphertext alphabets. |
void |
initKey(java.lang.String keyspec,
boolean removeDuplicates)
Initializes the keyspec, keyword and alphabet instance variables given a specification of the form keydata/plainspec/cipherspec. |
void |
printAlphabets()
Prints both the cipher and plain alphabets to the System console. |
static java.lang.String |
removeDuplicateChars(java.lang.String key)
A utility method to remove duplicate characters from a string. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String keyspec
An example would be xylophone/az/AZ where the keydata in this case is the keyword "xylophone", the plaintext alphabet consists of the lowercase letters a..z, and the ciphertext alphabet consists of the uppercase letters A..Z. In this case, the encryption algorithm will map letters from a..z to A..Z, and the decryption algorithm will perform the reverse mapping.
Another example would be xylophone/az. In this case the keyword is "xylophone" and both the plaintext and ciphertext alphabets are the lowercase letters a..z. In this case both encryption and decryption are performed by mapping from the set of characters a..z onto itself.
protected java.lang.String keyword
protected Alphabet alphabet
protected Alphabet cipherAlphabet
protected char[] plainAlphabet
protected char[] ciphAlphabet
protected int blocksize
protected java.lang.String keyDescriptorPrompt
Constructor Detail |
public HistoricalKey()
Method Detail |
public static final HistoricalKey getInstance(java.lang.String algorithm, java.lang.String provider)
algorithm,
- a String giving the algorithm nameprovider,
- a String giving the provider namepublic void initKey(java.lang.String keyspec, boolean removeDuplicates) throws java.lang.Exception
keyspec
- is a String specifying algorithm-specific key data
-- for example the shift value for a Caesar cipher -- and an
specification of the set of characters used in encryption.public abstract void init(java.lang.String keyspec) throws java.lang.Exception
public abstract java.lang.String getAlgorithm()
public java.lang.String getKeyword()
public Alphabet getAlphabet()
public Alphabet getCTAlphabet()
public int getBlocksize()
public java.lang.String getKeyDescriptorPrompt()
public static java.lang.String removeDuplicateChars(java.lang.String key)
protected void initAlphabets() throws java.lang.Exception
public char[] getCiphAlphabet()
public char[] getPlainAlphabet()
public void printAlphabets()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |