org.logi.crypto.keys
Class CaesarKey

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.keys.K
              |
              +--org.logi.crypto.keys.SymmetricKey
                    |
                    +--org.logi.crypto.keys.CaesarKey
All Implemented Interfaces:
CipherKey, Key

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 given no known plaintext.

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@logi.org)

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Constructor Summary
CaesarKey()
          Create a new random Caesar key.
CaesarKey(byte shift)
          Create a new Caesar key with the specified shift.
 
Method Summary
 int cipherBlockSize()
          The block-size for the Caesar cipher is one byte.
 void decrypt(byte[] source, int i, byte[] dest, int j)
          Decrypt one byte.
 void encrypt(byte[] source, int i, byte[] dest, int j)
          Encrypt one byte.
 boolean equals(java.lang.Object o)
          Return true iff the two keys are equivalent.
 java.lang.String getAlgorithm()
          The name of the algorithm is "Caesar".
 int getSize()
          The key-size for the Caesar cipher is 1 byte.
static CaesarKey parseCDS(java.lang.String key)
          If "CaesarKey( key )" is a valid CDS for a CaesarKey, then CaesarKey.parseCDS(key) will return the described CaesarKey object.
 int plainBlockSize()
          The block-size for the Caesar cipher is one byte.
 java.lang.String toString()
          Return a CDS for this key.
 
Methods inherited from class org.logi.crypto.keys.SymmetricKey
isPrivate, matches
 
Methods inherited from class org.logi.crypto.keys.K
getFingerprint, getFingerprint, hashCode, matchFingerprint, matchFingerprint
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, readBlock, readInt, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.logi.crypto.keys.Key
getFingerprint, getFingerprint, hashCode, isPrivate, matches, matchFingerprint, matchFingerprint
 

Constructor Detail

CaesarKey

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

CaesarKey

public CaesarKey()
Create a new random Caesar key.
Method Detail

parseCDS

public static CaesarKey parseCDS(java.lang.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:
Crypto.fromString(String)

getSize

public int getSize()
The key-size for the Caesar cipher is 1 byte.
Specified by:
getSize in interface Key

plainBlockSize

public final int plainBlockSize()
The block-size for the Caesar cipher is one byte.
Specified by:
plainBlockSize in interface CipherKey

cipherBlockSize

public final int cipherBlockSize()
The block-size for the Caesar cipher is one byte.
Specified by:
cipherBlockSize in interface CipherKey

getAlgorithm

public java.lang.String getAlgorithm()
The name of the algorithm is "Caesar".
Specified by:
getAlgorithm in interface Key

equals

public final boolean equals(java.lang.Object o)
Return true iff the two keys are equivalent.
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Return a CDS for this key.
Overrides:
toString in class java.lang.Object
See Also:
Crypto.fromString(java.io.Reader)

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].
Specified by:
encrypt in interface CipherKey

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].
Specified by:
decrypt in interface CipherKey


Copyright 1997-2000 Logi Ragnarsson