hcrypto.engines
Class AffineKey

java.lang.Object
  extended by hcrypto.cipher.HistoricalKey
      extended by hcrypto.engines.AffineKey

public class AffineKey
extends HistoricalKey

Represents a key for an Affine cipher. The key is entirely represented by two integers, a and b, which serve as variables in the Affine functions: encrypt(x) = ax + b mod N and decrypt(y) = inverse_of(a) * (y - b) mod N where N = size of the alphabet.

For a good overview of Affine cipher see the discussion on Wikipedia.

Example key and argument: 3,3/az+AZ yourTEXThere

NOTE: The Affine algorithm does not accept digits (0..9) as part of the alphabet.

This implementation of the Affine cipher is restricted to condition that the plaintext alphabet and ciphertext alphabet must have the same size.

See also:


AffineEngine
Alphabet


Field Summary
static java.lang.String DEFAULT_KEY_DESCRIPTOR_PROMPT_STRING
          A description for an Affine Key.
static java.lang.String DEFAULT_KEYWORD_STRING
          Default key values.
 
Constructor Summary
AffineKey()
           
 
Method Summary
 java.lang.String getAlgorithm()
          Returns the algorithm name "Affine".
 int getKeyA()
          Returns the keyA value for the Affine function.
 int getKeyB()
          Returns the keyB value for the Affine function.
 void init(java.lang.String keyspec)
          Creates an AffineKey with the specified keyspec.
 void init(java.lang.String keyword, Alphabet alpha1, Alphabet alpha2)
          Initializes the AffineKey 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 an Affine Key.

See Also:
Constant Field Values

DEFAULT_KEYWORD_STRING

public static final java.lang.String DEFAULT_KEYWORD_STRING
Default key values.

See Also:
Constant Field Values
Constructor Detail

AffineKey

public AffineKey()
Method Detail

init

public void init(java.lang.String keyspec)
          throws java.lang.Exception
Creates an AffineKey with the specified keyspec.

Specified by:
init in class HistoricalKey
Parameters:
keyspec - takes the form "integer,integer/alphabet", i.e. "5,21/az" for example, which would be mapped into the instance variables keyword as a String with the value "5,21", and alphabet as a String with the value "az".
Throws:
java.lang.Exception

init

public void init(java.lang.String keyword,
                 Alphabet alpha1,
                 Alphabet alpha2)
          throws java.lang.Exception
Initializes the AffineKey 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

getAlgorithm

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

Specified by:
getAlgorithm in class HistoricalKey

getKeyA

public int getKeyA()
Returns the keyA value for the Affine function.


getKeyB

public int getKeyB()
Returns the keyB value for the Affine function.