hcrypto.cipher
Class HistoricalSecretKey

java.lang.Object
  |
  +--hcrypto.cipher.HistoricalSecretKey

public abstract class HistoricalSecretKey
extends java.lang.Object

This abstract class provides a partial implementation of the HistoricalKey interface by providing default implementations of the getKeyword(), getAlphabet(), and getBlocksize() methods.

The HistoricalSecretKey() 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");
 


Field Summary
protected  Alphabet alphabet
          This instance variable stores a reference to the particular characters for which this cipher is defined.
protected  int blocksize
          Stores the blocksize.
protected  java.lang.String keyDescriptorPrompt
          Stores a prompt that can be used by the interface that describes the type of key that would be used for a particular cipher.
protected  java.lang.String keyspec
          A keyspec takes the form keydata/alphabetspec.
protected  java.lang.String keyword
          Many historical ciphers use a keyword as part (or all) of the key.
 
Constructor Summary
HistoricalSecretKey()
           
 
Method Summary
abstract  java.lang.String getAlgorithm()
          This abstract method should be implemented in the subclass.
 Alphabet getAlphabet()
          Returns a reference to this key's alphabet.
 int getBlocksize()
          Returns this cipher's blocksize.
static HistoricalSecretKey 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.
abstract  void init(java.lang.String keyspec)
          This abstract method should be implemented in the subclass.
 void initKey(java.lang.String keyspec)
          Initializes the keyspec, keyword and alphabet instance variables given a specification of the form keydata/alphabetspec.
protected  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

keyspec

protected java.lang.String keyspec
A keyspec takes the form keydata/alphabetspec. An example would be xylophone/azAZ09 where the keydata in this case is a keyword and the alphabet specified is the alphanumeric characters.

keyword

protected java.lang.String keyword
Many historical ciphers use a keyword as part (or all) of the key. For example, substitution and Vigenere ciphers use the keyword to initialize the cipher alphabet.

alphabet

protected Alphabet alphabet
This instance variable stores a reference to the particular characters for which this cipher is defined.

blocksize

protected int blocksize
Stores the blocksize. Character ciphers (such as Vigener, Caesar) have a blocksize of 1. Block ciphers (such as Playfair) have a blocksize that is greater than 1.

keyDescriptorPrompt

protected java.lang.String keyDescriptorPrompt
Stores a prompt that can be used by the interface that describes the type of key that would be used for a particular cipher. For example, Caesar cipher would prompt with "positive integer"
Constructor Detail

HistoricalSecretKey

public HistoricalSecretKey()
Method Detail

getInstance

public static final HistoricalSecretKey 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)
             throws java.lang.Exception
Initializes the keyspec, keyword and alphabet instance variables given a specification of the form keydata/alphabetspec.
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.

init

public abstract void init(java.lang.String keyspec)
This abstract method should be implemented in the subclass.

getAlgorithm

public abstract java.lang.String getAlgorithm()
This abstract method should be implemented in the 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.

getBlocksize

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

getKeyDescriptorPrompt

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

removeDuplicateChars

protected 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".