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)
-
CaesarKey()
- Create a new random Caesar key.
-
CaesarKey(byte)
- Create a new Caesar key with the specified shift.
-
cipherBlockSize()
- The block-size for the Caesar cipher is one byte.
-
decrypt(byte[], int, byte[], int)
- Decrypt one byte.
-
encrypt(byte[], int, byte[], int)
- Encrypt one byte.
-
equals(Object)
- Return true iff the two keys are eqivalent.
-
getAlgorithm()
- The name of the algorithm is "Caesar".
-
getSize()
- The key-size for the Caesar cipher is 8 bytes.
-
parseCDS(String)
- If "CaesarKey( key )" is a valid CDS for a CaesarKey, then
CaesarKey.parseCDS(key) will return the described CaesarKey object.
-
plainBlockSize()
- The block-size for the Caesar cipher is one byte.
-
toString()
- Return a CDS for this key.
CaesarKey
public CaesarKey(byte shift)
- Create a new Caesar key with the specified shift.
CaesarKey
public CaesarKey()
- Create a new random Caesar key.
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
getSize
public int getSize()
- The key-size for the Caesar cipher is 8 bytes.
- Overrides:
- getSize in class K
plainBlockSize
public final int plainBlockSize()
- The block-size for the Caesar cipher is one byte.
cipherBlockSize
public final int cipherBlockSize()
- The block-size for the Caesar cipher is one byte.
getAlgorithm
public String getAlgorithm()
- The name of the algorithm is "Caesar".
- Overrides:
- getAlgorithm in class K
equals
public final boolean equals(Object o)
- Return true iff the two keys are eqivalent.
- Overrides:
- equals in class Object
toString
public String toString()
- Return a CDS for this key.
- Overrides:
- toString in class Object
- See Also:
- fromString
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]
.
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