hcrypto.engines
Class AffineEngine

java.lang.Object
  extended by hcrypto.cipher.CipherEngine
      extended by hcrypto.cipher.BlockCipher
          extended by hcrypto.engines.AffineEngine

public class AffineEngine
extends BlockCipher

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, az+AZ.

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

The AffineKey is composed of two integers: A_E_Key and B_E_Key which represent "encryption 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


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.
 
Methods inherited from class hcrypto.cipher.CipherEngine
getAlphabetRangeOptions
 
Methods inherited from class java.lang.Object
equals, 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

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.

Parameters:
s - the String to be encrypted
Throws:
java.lang.Exception

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.

Parameters:
s - the String to be decrypted
Throws:
java.lang.Exception