hcrypto.engines
Class PlayfairEngine

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

public class PlayfairEngine
extends BlockCipher

This class implements the Playfair encryption algorithm. In this algorithm, pairs of individual letters from the range a..z are mapped into pairs of symbols taken from a 2-dimensional square matrix. The letter 'j' is dropped from the ciphertext alphabet. Thus, in this implementation, the ciphertext alphabet consists of the letters a..z, minus the letter 'j'. A keyword is used to vary the distribution of the letters in the matrix.

For example: If the keyword is "keyword", the matrix would look like this:

   
k e y w o 
r d a b c 
f g h i l
m n p q s
t u v x z

The following rules are used to perform the mapping:

1. If both letters happen to be in the same row, the letters immediately to the right of each letter are used. The letter to the "right" of the last letter in a row is the first letter in that same row. For example, given the above square, "ey" would be encrypted as "yw".

2. If both letters are in the same column, the letters immediately below each letter are used. The letter "below" a bottom letter is the top letter of the same column. For example, given the above square, "ed" would be encrypted by "dg".

3. If the two letters are in different rows and in different columns, each letter is replaced by the letter in the same row that is also in the column occupied by the other letter. For example, for the above square, "dh" would be encrypted by "ag".


PlayfairKey
Alphabet


Fields inherited from class hcrypto.cipher.BlockCipher
alphabet, blocksize, cipherAlphabet
 
Fields inherited from class hcrypto.cipher.CipherEngine
alphabetRangeOptions
 
Constructor Summary
PlayfairEngine()
          Creates a PlayfairEngine and sets the alphabetRangeOptions instance variable to "100000", which translates to the "az" alphabet option only for both plaintext and ciphertext.
 
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 PlayfairEngine 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

PlayfairEngine

public PlayfairEngine()
Creates a PlayfairEngine and sets the alphabetRangeOptions instance variable to "100000", which translates to the "az" alphabet option only for both plaintext and ciphertext.
Method Detail

engineInit

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

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