sam.cipher
Class WarFactory.War

java.lang.Object
  |
  +--sam.cipher.Cipher
        |
        +--sam.cipher.WarFactory.War
Enclosing class:
WarFactory

public class WarFactory.War
extends Cipher

Actual War implementation


Nested Class Summary
 
Nested classes inherited from class sam.cipher.Cipher
Cipher.ByteArrayFilter, Cipher.Error
 
Field Summary
 
Fields inherited from class sam.cipher.Cipher
DECRYPT, EMPTY, ENCRYPT, INVERSE, key, REGISTRY
 
Constructor Summary
protected WarFactory.War(WarFactory.Key key)
          Builds a new War cipher.
 
Method Summary
protected  void decrypt(byte[] data, int offset, sam.cipher.Key key)
          Decrypts exactly one block of ciphertext.
protected  void encrypt(byte[] data, int offset, sam.cipher.Key key)
          Encrypts exactly one block of plaintext.
 int getPreferredSize(int size)
          Specifiy preferred buffer size.
protected  void rotate(byte[] data, int offset, boolean[] directions)
          Main permutation routine.
 
Methods inherited from class sam.cipher.Cipher
cipher, cipher, fill, main, store, store, storeReversed, streamTest, test, unstoreInt, unstoreLong, unstoreReversedLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WarFactory.War

protected WarFactory.War(WarFactory.Key key)
Builds a new War cipher.

Parameters:
key - the fixed key to be used (either encryption or decryption key)
See Also:
Key
Method Detail

getPreferredSize

public int getPreferredSize(int size)
Description copied from class: Cipher
Specifiy preferred buffer size.

May return a fixed value, ignoring suggested size (e.g. return 16;).

By default, this implementation simply returns its argument unchanged.

Overrides:
getPreferredSize in class Cipher
Parameters:
size - proposed buffer size (in bytes)
Returns:
adjusted buffer size (in bytes)

encrypt

protected void encrypt(byte[] data,
                       int offset,
                       sam.cipher.Key key)
Encrypts exactly one block of plaintext.

Specified by:
encrypt in class Cipher
Parameters:
data - The plaintext.
key - The session key to use for encryption.

decrypt

protected void decrypt(byte[] data,
                       int offset,
                       sam.cipher.Key key)
Decrypts exactly one block of ciphertext.

Specified by:
decrypt in class Cipher
Parameters:
data - The plaintext.
key - The session key to use for decryption.

rotate

protected void rotate(byte[] data,
                      int offset,
                      boolean[] directions)
Main permutation routine.

This works as follows: given a square


	     A B
	     C D
	   
it first rotates block either clockwise

	     C A
	     D B
	   
or counter-clockwise

	     B D
	     A C
	   
according to directions's lowest bit. It then recurses into each of the four squares for the next bits.