|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sam.cipher.Key
General purpose key class.
This class's data is immutable, and so should be subclasses.
You may create a sub-class in the following way:
class MyKey extends Cipher.Key { public MyKey(long[] longs) { super( makeKey(longs), 27 ); // } private static long[] makeKey(long[] longs) { long[] key = new long[39]; ... // Use 64 bits of 'longs[i]' to generate 27 bits in 'key[j]' return key; } public Key inverse() { return new MyKey(...); } }
Nested Class Summary | |
static class |
Key.Mode
Parsing mode for converting characters to significant bits. |
Field Summary | |
protected boolean[] |
asBooleans
|
protected byte[] |
asBytes
|
static Key.Mode |
ASCII
One char issues 8 bits |
protected int[] |
asInts
|
protected long[] |
asLongs
|
protected short[] |
asShorts
|
static Key.Mode |
BINARY
One char ( 0,1 ) issues 1 bit |
protected long[] |
bits
Actual bits. |
protected int |
bitsPerLong
Number of significant bits per long of bits . |
boolean |
direction
Reports wether this is an encryption- or a decryption-key. |
static sam.cipher.Key |
EMPTY
One char issues no single bit |
static Key.Mode |
HEXA
One char ( 0,1,..9,A,..F ) issues 4 bits |
static Key.Mode |
IGNORE
One char issues no bit at all |
protected int |
mask
Mask for keeping only the significant bits of a long . |
static Key.Mode |
OCTAL
One char ( 0,1,..,7 ) issues 3 bits |
static Key.Mode |
PLAIN
One char issues 6 bits. |
static Key.Mode |
UNICODE
One char issues 16 bits |
Constructor Summary | |
protected |
Key(boolean[] bits)
Builds a new key. |
|
Key(long[] bits)
Builds a new key. |
protected |
Key(long[] bits,
int bitsPerLong)
Builds a new key. |
protected |
Key(long[] bits,
int bitsPerLong,
boolean direction)
Builds a new key. |
|
Key(java.lang.String password,
Key.Mode mode,
int bitsPerLong)
Builds a new key. |
Method Summary | |
boolean |
equals(java.lang.Object object)
General-purpose. |
byte[] |
expandToBytes()
|
int[] |
expandToInts()
|
long[] |
expandToLongs()
|
short[] |
expandToShorts()
|
boolean[] |
get1()
|
short[] |
get16()
|
int[] |
get32()
|
long[] |
get64()
|
byte[] |
get8()
|
boolean[] |
getBits()
|
boolean[] |
getBooleans()
|
byte[] |
getBytes()
|
int[] |
getInts()
|
long[] |
getLongs()
|
short[] |
getShorts()
|
sam.cipher.Key |
inverse()
Inverses this key. |
boolean |
isEmpty()
Wether this key is empty |
protected static long[] |
parse(java.lang.String password,
Key.Mode mode,
int bitsPerLong)
Parses a String passphrase to a long[] array key material. |
protected static byte[] |
toBytes(long[] longs)
Converts an array of long s to an array of byte s, without any loss of data. |
protected static long[] |
toLongs(boolean[] booleans)
Converts an array of boolean s to an array of long s, without
any loss of data. |
protected static long[] |
toLongs(byte[] bytes)
Converts an array of byte s to an array of long s, without
any loss of data. |
protected static long[] |
toLongs(char[] chars)
Converts an array of char s to an array of long s, without
any loss of data. |
protected static long[] |
toLongs(int[] ints)
Converts an array of int s to an array of long s, without
any loss of data. |
protected static long[] |
toLongs(short[] shorts)
Converts an array of short s to an array of long s, without
any loss of data. |
java.lang.String |
toPassword()
Unparses a key to a passphrase. |
java.lang.String |
toPassword(Key.Mode mode)
Unparses a key to a passphrase. |
java.lang.String |
toString()
Gets a human-readable description of this key. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final sam.cipher.Key EMPTY
public static final Key.Mode UNICODE
public static final Key.Mode ASCII
public static final Key.Mode PLAIN
Default mode for keyboard-entered passworsd.
public static final Key.Mode BINARY
0,1
) issues 1 bit
public static final Key.Mode OCTAL
0,1,..,7
) issues 3 bits
public static final Key.Mode HEXA
0,1,..9,A,..F
) issues 4 bits
public static final Key.Mode IGNORE
public final boolean direction
protected final long[] bits
protected final int bitsPerLong
long
of bits
.
protected final int mask
long
.
protected final boolean[] asBooleans
protected final byte[] asBytes
protected final short[] asShorts
protected final int[] asInts
protected final long[] asLongs
Constructor Detail |
public Key(java.lang.String password, Key.Mode mode, int bitsPerLong)
password
- the plain text passphrasemode
- parsing modebitsPerLong
- desired number of bits to be stored per int (max 32).parse
protected Key(boolean[] bits)
bits
- the boolean[]
array of bits composing the key materialpublic Key(long[] bits)
bits
- the long[]
array of 64-bit groups composing the key material
Note that this constructor must be public as sam.cipher.Key
might
be the default key used.protected Key(long[] bits, int bitsPerLong)
bits
- the long[]
array of bit groups composing the key materialbitsPerLong
- the number of significant bits per 64-bits long
to be usedprotected Key(long[] bits, int bitsPerLong, boolean direction)
bits
- the long[]
array of bit groups composing the key materialbitsPerLong
- the number of significant bits per 64-bits long
to be useddirection
- either Cipher.ENCRYPT
or Cipher.DECRYPT
Method Detail |
public boolean isEmpty()
public sam.cipher.Key inverse()
This implementation simply returns this
.
public java.lang.String toString()
toString
in class java.lang.Object
"Key(8|0xff)[0011011000101]"
.toPassword(sam.cipher.Key.Mode)
public java.lang.String toPassword(Key.Mode mode)
mode
- the parsing mode.
public java.lang.String toPassword()
PLAIN
Warning: this methods returns the actual key material
public boolean[] get1()
getBooleans()
public boolean[] getBits()
getBooleans()
public boolean[] getBooleans()
boolean[] array.
public byte[] get8()
getBytes()
public byte[] getBytes()
byte[] array.
public byte[] expandToBytes()
public short[] get16()
getShorts()
public short[] getShorts()
short[] array.
public short[] expandToShorts()
public int[] get32()
getInts()
public int[] getInts()
int[] array.
public int[] expandToInts()
public long[] get64()
getLongs()
public long[] getLongs()
long[] array.
public long[] expandToLongs()
long[] array.
public boolean equals(java.lang.Object object)
Required to be overriden by subclasses only if specific instance data are declared.
equals
in class java.lang.Object
protected static long[] parse(java.lang.String password, Key.Mode mode, int bitsPerLong)
String
passphrase to a long[]
array key material.
password
- the password to be parsedmode
- the parsing modebitsPerLong
- the desired number of significant bits to be stored in each resulting long
.
Note that the actual number of significant bits of the password is part of the mode
parameter,
the resulting array is thus sized accordingly to the bitsPerLong
parameter.
protected static byte[] toBytes(long[] longs)
long
s to an array of byte
s, without any loss of data.
longs
- the source array of 64-bits full long
s.
byte
s.protected static long[] toLongs(boolean[] booleans)
boolean
s to an array of long
s, without
any loss of data.
booleans
- the source array of 1-bit full boolean
s.
long
s.protected static long[] toLongs(byte[] bytes)
byte
s to an array of long
s, without
any loss of data.
bytes
- the source array of 8-bits full byte
s.
long
s.protected static long[] toLongs(short[] shorts)
short
s to an array of long
s, without
any loss of data.
shorts
- the source array of 16-bits full short
s.
long
s.protected static long[] toLongs(char[] chars)
char
s to an array of long
s, without
any loss of data.
long
s.protected static long[] toLongs(int[] ints)
int
s to an array of long
s, without
any loss of data.
ints
- the source array of 32-bits full int
s.
long
s.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |