hcrypto.engines
Class CaesarEngine

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

public class CaesarEngine
extends BlockCipher

This class implements the Caesar cipher algorithm for any range of alphabets, including az, AZ, azAZ, azAZ09, printable, and ASCII. As in the traditional Caesar cipher, letters in the plaintext are shifted by an integral value. Thus for the traditional alphabet, az or AZ, if the shift is 3, plaintext 'a' would become 'd' and plaintext 'A' would become 'D'.

This implementation of Caesar cipher is generalized to work for any ASCII characters by scaling the modulus to the appropriate character range depending on the plaintext or ciphertext character. For example, if the character is the digit '5', then the modulus must be 10 in order to insure that '5' is mapped onto another digit by the formula:

       (char)((('5' - '0') + shift) % 10 + '0')
 
The Alphabet class contains methods, getLowBound('5') and getRange('5'), which allow this mapping to be generalized to:
       (char)(((ch - low) + shift) % range + low)
 
so that the shift will apply to any character in the character set. Thus the mapping is always based on the low character in the appropriate character range -- 'a' for range az, '0' for range 09, ASCII 32 for range printable -- and the appropriate modulus for the range -- 10, 26, etc.

See also:


CaesarKey
Alphabet


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

CaesarEngine

public CaesarEngine()
Creates a CaesarEngine and sets the alphabetRangeOptions instance variable to "111111", which translates to all six alphabet options for both the plaintext and ciphertext alphabets.
Method Detail

engineInit

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

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