sam.cipher
Class WarFactory

java.lang.Object
  |
  +--sam.cipher.Factory
        |
        +--sam.cipher.WarFactory

public class WarFactory
extends Factory

Generic variable-size sam.cipher.War factory. This allows for dynamic instantiation of War of various sizes.

War stands for Wide Area Rotator

This class implements a cipher that given a key of size n*p bits shuffles a data-buffer of size 4^p bytes n times. For the actual implementation, p = 8 so that the buffer is 65536 bytes wide.

Easy to break out by brute force (due to small keys: for example n*8bits, implying only n*65536 attack cases, which is not so big after all), it is not intended to be used solely, but rather as a destructuring step in the ciphering stack.


Nested Class Summary
protected  class WarFactory.Key
          General purpose key class.
 class WarFactory.War
          Actual War implementation
 
Field Summary
 int keyBits
          Number of bits per key element
 int length
          Total buffer length, i.e.
 int size
          Size of the square composing the buffer
 
Fields inherited from class sam.cipher.Factory
description, name
 
Constructor Summary
WarFactory(int keyBits)
          Builds a variable-size new War factory.
 
Method Summary
 int getPreferredKeySize(int size)
          Specifies preferred key size, in bits.
protected  sam.cipher.Cipher make(long[] material, boolean direction)
          Instantiates a new WarFactory.War cipher.
protected  boolean[] resize(long[] bits)
          Resizes key to the uppest lower multiple of keyBits If the current size is larger, the key is truncated.
 
Methods inherited from class sam.cipher.Factory
highestIn, highestMultiple, ranged, resizeKey, resizeKeyToPreferredSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyBits

public final int keyBits
Number of bits per key element


size

public final int size
Size of the square composing the buffer


length

public final int length
Total buffer length, i.e. size^2

Constructor Detail

WarFactory

public WarFactory(int keyBits)
Builds a variable-size new War factory.

Parameters:
keyBits - Number of bits per key element Note that this also registers thie factory
See Also:
Registry.register(sam.cipher.Factory)
Method Detail

getPreferredKeySize

public int getPreferredKeySize(int size)
Description copied from class: Factory
Specifies preferred key size, in bits. This shall be overridden to match legal key sizes of specific algorithms.

Overrides:
getPreferredKeySize in class Factory
Parameters:
size - the suggested key size as computed from the password length
Returns:
a key size suited to this cipher implementation
See Also:
Key, Factory.highestMultiple(int, int)

make

protected sam.cipher.Cipher make(long[] material,
                                 boolean direction)
                          throws java.lang.Error
Instantiates a new WarFactory.War cipher.

Specified by:
make in class Factory
Parameters:
material - the key as full longs, its length having been retrofitted by the getPreferredKeySize method.
direction - true if encrypting, false otherwise (decrypting).
Throws:
java.lang.Error - in case of impossible instantiation
See Also:
Cipher.ENCRYPT, Cipher.DECRYPT

resize

protected boolean[] resize(long[] bits)
                    throws java.lang.Error
Resizes key to the uppest lower multiple of keyBits If the current size is larger, the key is truncated. If it is smaller, the key is concatenated to itself until it is large enough.

Parameters:
bits - the key material to be resized
Throws:
java.lang.Error - if this key is empty and expected size is not