|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecthcrypto.cipher.CipherEngine
hcrypto.cipher.BlockCipher
hcrypto.engines.CaesarEngine
public class CaesarEngine
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
| 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. |
| 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 |
|---|
public CaesarEngine()
| Method Detail |
|---|
public java.lang.String engineEncode(java.lang.String s)
throws java.lang.Exception
s - the String to be encrypted
java.lang.Exception
public java.lang.String engineDecode(java.lang.String s)
throws java.lang.Exception
s - the String to be decrypted
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||