hcrypto.engines
Class AffineEngine

java.lang.Object
  |
  +--hcrypto.cipher.CipherEngine
        |
        +--hcrypto.cipher.BlockCipher
              |
              +--hcrypto.engines.AffineEngine

public class AffineEngine
extends BlockCipher

This class implements an Affine cipher algorithm (a special case of a Substitution Cipher that encrypts and decrypts a character based on two Affine functions) for any of three alphabet ranges including az, AZ, azAZ. The AffineKey is composd of two integers: A_E_Key and B_E_Key which represent "encyption key A" and "encryption key B" respectfully. Two additional keys are created in this class for decrypting: A_D_Key and B_D_Key.

A_D_Key is created by computing the multiplicative inverse (mod 26) of the A_E_Key with a private function.

B_D_Key is created by subtracting the B_E_Key from 26, modulus 26.

     B_D_Key = (26 - B_E_Key) % 26 )
 

engineEncode(String s) performs the following function:

encrypt(x) = ax + b mod 26

engineDecode(String s) performs the following function:

decrypt(y) = inverse of (a) * (y - b) mod 26

See also:


AffineKey
Alphabet


Fields inherited from class hcrypto.cipher.BlockCipher
alphabet, blocksize, cipherAlphabet
 
Fields inherited from class hcrypto.cipher.CipherEngine
alphabetRangeOptions
 
Constructor Summary
AffineEngine()
          Creates an AffineEngine and sets the alphabetRangeOptions instance variable to "110000", which translates to the "az+AZ"alphabet option for both the plaintext and ciphertext alphabets.
 
Method Summary
 java.lang.String engineDecode(java.lang.String s)
          Returns an encoded String for the specified String.
 java.lang.String engineEncode(java.lang.String s)
          Returns an encoded String for the specified String.
protected  void engineInit(HistoricalKey hKey)
          Initializes the AffineEngine with the specified hKey.
 
Methods inherited from class hcrypto.cipher.BlockCipher
decodeShift, encodeShift, engineDecrypt, engineDecryptFile, engineDecryptFile, engineEncrypt, engineEncryptFile, engineEncryptFile
 
Methods inherited from class hcrypto.cipher.CipherEngine
getAlphabetRangeOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AffineEngine

public AffineEngine()
Creates an AffineEngine and sets the alphabetRangeOptions instance variable to "110000", which translates to the "az+AZ"alphabet option for both the plaintext and ciphertext alphabets.
Method Detail

engineInit

protected void engineInit(HistoricalKey hKey)
                   throws java.lang.Exception
Initializes the AffineEngine with the specified hKey.
Overrides:
engineInit in class BlockCipher
Parameters:
hKey - a AffineKey.

engineEncode

public java.lang.String engineEncode(java.lang.String s)
                              throws java.lang.Exception
Returns an encoded String for the specified String. Characters which are not part of the chosen alphabet set are ignored.
Overrides:
engineEncode in class BlockCipher
Parameters:
s - the String to be encrypted

engineDecode

public java.lang.String engineDecode(java.lang.String s)
                              throws java.lang.Exception
Returns an encoded String for the specified String. Characters which are not part of the chosen alphabet set are ignored.
Overrides:
engineDecode in class BlockCipher
Parameters:
s - the String to be decrypted