hcrypto.engines
Class TranspositionEngine

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

public class TranspositionEngine
extends BlockCipher

This class implements a Transposition cipher algorithm for any range of alphabets, including az, AZ, azAZ, azAZ09, printable characters, and all ASCII. A keyword is retrieved from the "TranspositionKey.html">TranspositionKey class and stored in a String instance variable. The keyword consists of a series of positive integers, i.e. "3021".

Encryption involves transposing a plaintext character from a given message with another character from the same plain text message. The basic algorithm for encrypting is:

      StringBuffer sb = new StringBuffer(blocksize);
      for (int k = 0; k < keyword.length(); k++) {
          sb.setCharAt((int)(keyword.charAt(k) - '0'), s.charAt(k));
      }
      return sb;
 

Decryption basically involves the same algorithm, only with an inverted keyword (created and retrieved from the TranspositionKey class).

      StringBuffer sb = new StringBuffer(blocksize);
      for (int k = 0; k < keyword.length(); k++) {
          sb.setCharAt((int)(invertedKeyword.charAt(k) - '0'), s.charAt(k));
      }
      return sb;

Padding and blocksize are handled in the engineEncode(String s) and engineDecode(String s) methods

See also:


TranspositionKey
Alphabet


Fields inherited from class hcrypto.cipher.BlockCipher
alphabet, blocksize, cipherAlphabet
 
Fields inherited from class hcrypto.cipher.CipherEngine
alphabetRangeOptions
 
Constructor Summary
TranspositionEngine()
          Creates a TranspositionEngine 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 TranspositionEngine 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

TranspositionEngine

public TranspositionEngine()
Creates a TranspositionEngine 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 TranspositionEngine with the specified hKey.
Overrides:
engineInit in class BlockCipher
Parameters:
hKey - a TranspositionKey.

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