hcrypto.engines
Class SubstitutionEngine

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

public class SubstitutionEngine
extends BlockCipher

This class implements a keyword-based Substitution cipher algorithm for any range of alphabets, including az, AZ, azAZ, azAZ09, printable characters, all ASCII, and any of the Unicode character sets. A plaintext alphabet is retrieved from the SubstitutionKey class and stored in a character array. A cipher alphabet is created by inserting the characters from the keyword into the first elements of the array, followed by all remaining characters in the particular alphabet.

Encryption involves replacing a plaintext character from a given message with a character from the cipher alphabet with the same index. Decrypting works in the reverse order.

      plainAlphabet = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,......];
      keyword = calm;
      cipherAlphabet = [c,a,l,m,b,d,e,f,g,h,i,j,k,n,o,p,......];
      
      engineEncrypt("cab") == "lca"
      engineDecrypt("lca") == "cab"
 

See also:


SubstitutionKey
Alphabet


Fields inherited from class hcrypto.cipher.BlockCipher
alphabet, blocksize, cipherAlphabet
 
Fields inherited from class hcrypto.cipher.CipherEngine
alphabetRangeOptions
 
Constructor Summary
SubstitutionEngine()
          Creates a SubstitutionEngine and sets the alphabetRangeOptions instance variable to "111111", which translates to all six alphabet options.
 
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 SubstitutionEngine 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

SubstitutionEngine

public SubstitutionEngine()
Creates a SubstitutionEngine and sets the alphabetRangeOptions instance variable to "111111", which translates to all six alphabet options.
Method Detail

engineInit

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

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