All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class is.logi.crypto.keys.CaesarKey

java.lang.Object
   |
   +----is.logi.crypto.Crypto
           |
           +----is.logi.crypto.keys.K
                   |
                   +----is.logi.crypto.keys.SymmetricKey
                           |
                           +----is.logi.crypto.keys.CaesarKey

public final class CaesarKey
extends SymmetricKey
implements CipherKey
The Caesar algorithm is supposedly the one Julius Caesar used by hand many centuries ago. As you can imagine, this is NOT A STRONG CIPHER, but included only to show how to write a very simple Key class for the logi.crypto package. Often, the first assignment given to cryptography students is to break this cipher.

Data is encrypted byte-by-byte by adding a constant value to it and taking the 8 lowest order bits.

The CDS for a CaesarKey object is CaesarKey(n) where n is a value in the range 0..255.

Author:
Logi Ragnarsson (logir@hi.is)

Constructor Index

 o CaesarKey()
Create a new random Caesar key.
 o CaesarKey(byte)
Create a new Caesar key with the specified shift.

Method Index

 o cipherBlockSize()
The block-size for the Caesar cipher is one byte.
 o decrypt(byte[], int, byte[], int)
Decrypt one byte.
 o encrypt(byte[], int, byte[], int)
Encrypt one byte.
 o equals(Object)
Return true iff the two keys are eqivalent.
 o getAlgorithm()
The name of the algorithm is "Caesar".
 o getSize()
The key-size for the Caesar cipher is 8 bytes.
 o parseCDS(String)
If "CaesarKey( key )" is a valid CDS for a CaesarKey, then CaesarKey.parseCDS(key) will return the described CaesarKey object.
 o plainBlockSize()
The block-size for the Caesar cipher is one byte.
 o toString()
Return a CDS for this key.

Constructors

 o CaesarKey
 public CaesarKey(byte shift)
Create a new Caesar key with the specified shift.

 o CaesarKey
 public CaesarKey()
Create a new random Caesar key.

Methods

 o parseCDS
 public static CaesarKey parseCDS(String key) throws InvalidCDSException
If "CaesarKey( key )" is a valid CDS for a CaesarKey, then CaesarKey.parseCDS(key) will return the described CaesarKey object.

A valid CDS can be created by calling the CaesarKey.toString() method.

Throws: InvalidCDSException
if the CDS is malformed.
See Also:
fromString
 o getSize
 public int getSize()
The key-size for the Caesar cipher is 8 bytes.

Overrides:
getSize in class K
 o plainBlockSize
 public final int plainBlockSize()
The block-size for the Caesar cipher is one byte.

 o cipherBlockSize
 public final int cipherBlockSize()
The block-size for the Caesar cipher is one byte.

 o getAlgorithm
 public String getAlgorithm()
The name of the algorithm is "Caesar".

Overrides:
getAlgorithm in class K
 o equals
 public final boolean equals(Object o)
Return true iff the two keys are eqivalent.

Overrides:
equals in class Object
 o toString
 public String toString()
Return a CDS for this key.

Overrides:
toString in class Object
See Also:
fromString
 o encrypt
 public final void encrypt(byte source[],
                           int i,
                           byte dest[],
                           int j)
Encrypt one byte. source[i] is encrypted and put in dest[j].

 o decrypt
 public final void decrypt(byte source[],
                           int i,
                           byte dest[],
                           int j)
Decrypt one byte. source[i] is decrypted and put in dest[j].


All Packages  Class Hierarchy  This Package  Previous  Next  Index