hcrypto.cipher
Class HistoricalKey

java.lang.Object
  extended by hcrypto.cipher.HistoricalKey
Direct Known Subclasses:
AffineKey, CaesarKey, CaesarKey, NullKey, PlayfairKey, PolySubstitutionKey, RailfenceKey, SubstitutionKey, TranspositionKey, VigenereKey

public abstract class HistoricalKey
extends java.lang.Object

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.

AlgorithmKeydataAlphabetSpec
CaesarshiftazAZ09
Substitutionkeywordprintable
Affinea,baz

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");
 


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[] getCipherKey()
          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[] getPlainKey()
          Returns the plaintext alphabet.
abstract  void init(java.lang.String keyspec)
          This abstract method should be implemented in the algorithm-specific subclass.
abstract  void init(java.lang.String keyword, Alphabet alpha1, Alphabet alpha2)
          ADDED: 4/5/03 by RAM This should be implemented in the subclass.
 void initKey(java.lang.String keyword, Alphabet alpha1, Alphabet alpha2)
          ADDED: 4/5/03 by RAM Initializes the key given the keyword and preexisting alphabete.
 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.
static java.lang.String invertKey(java.lang.String key)
          invertKey() inverts a key from decrypt to encrypt
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HistoricalKey

public HistoricalKey()
Method Detail

getInstance

public static final 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.

Parameters:
algorithm, - a String giving the algorithm name
provider, - a String giving the provider name

initKey

public void initKey(java.lang.String keyspec,
                    boolean removeDuplicates)
             throws java.lang.Exception
Initializes the keyspec, keyword and alphabet instance variables given a specification of the form keydata/plainspec/cipherspec. It also initializes the char arrays.

Parameters:
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.
Throws:
java.lang.Exception

initKey

public void initKey(java.lang.String keyword,
                    Alphabet alpha1,
                    Alphabet alpha2)
             throws java.lang.Exception
ADDED: 4/5/03 by RAM Initializes the key given the keyword and preexisting alphabete.

Parameters:
keyword - is a String specifying algorithm-specific key data
alpha1, - alpha2 are references to alphabets, alpha2 may identical to alpha1
Throws:
java.lang.Exception

init

public abstract void init(java.lang.String keyword,
                          Alphabet alpha1,
                          Alphabet alpha2)
                   throws java.lang.Exception
ADDED: 4/5/03 by RAM This should be implemented in the subclass.

Throws:
java.lang.Exception

init

public abstract void init(java.lang.String keyspec)
                   throws java.lang.Exception
This abstract method should be implemented in the algorithm-specific subclass.

Throws:
java.lang.Exception

getAlgorithm

public abstract java.lang.String getAlgorithm()
This abstract method should be implemented in the algorithm-specific subclass.


getKeyword

public java.lang.String getKeyword()
Returns the keyword for this key.


getAlphabet

public Alphabet getAlphabet()
Returns a reference to this key's alphabet.


getCTAlphabet

public Alphabet getCTAlphabet()
Returns a reference to this key's cipherAlphabet.


getBlocksize

public int getBlocksize()
Returns this cipher's blocksize.


getKeyDescriptorPrompt

public java.lang.String getKeyDescriptorPrompt()
Returns an interface prompt describing the key


removeDuplicateChars

public static java.lang.String removeDuplicateChars(java.lang.String key)
A utility method to remove duplicate characters from a string. For example, it would convert the passphrase "hello" to the keyword "helo".


getCipherKey

public char[] getCipherKey()
Returns the cipher alphabet.


getPlainKey

public char[] getPlainKey()
Returns the plaintext alphabet.


printAlphabets

public void printAlphabets()
Prints both the cipher and plain alphabets to the System console.


invertKey

public static java.lang.String invertKey(java.lang.String key)
invertKey() inverts a key from decrypt to encrypt