|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--hcrypto.cipher.HistoricalKey | +--hcrypto.engines.PlayfairKey
This class represents a key for a Playfair cipher. The key is entirely represented by a keyword. The key is inserted into a matrix of letters in the PlayfairEngine class for encrypting and decrypting.
For this implementation of the Playfair cipher the alphabet range is restricted to "az". In the ciphertext alphabet, the letter 'j' is omitted and j's in the plaintext message are changed to i's.
For example: If the keyword is "keyword", the matrix would look like this:
k e y w o r d a b c f g h i l m n p q s t u v x z
The following rules are used to perform the mapping:
1. If both letters happen to be in the same row, the letters immediately to the right of each letter are used. The letter to the "right" of the last letter in a row is the first letter in that same row. For example, given the above square, "ey" would be encrypted as "yw".
2. If both letters are in the same column, the letters immediately below each letter are used. The letter "below" a bottom letter is the top letter of the same column. For example, given the above square, "ed" would be encrypted by "dg".
3. If the two letters are in different rows and in different columns, each letter is replaced by the letter in the same row that is also in the column occupied by the other letter. For example, for the above square, "dh" would be encrypted by "ag".
See also:
PlayfairEngine
Alphabet
Field Summary | |
static java.lang.String |
DEFAULT_KEY_DESCRIPTOR_PROMPT_STRING
A keyword description. |
static java.lang.String |
DEFAULT_KEYWORD_STRING
A default keyword. |
Fields inherited from class hcrypto.cipher.HistoricalKey |
alphabet, blocksize, ciphAlphabet, cipherAlphabet, keyDescriptorPrompt, keyspec, keyword, plainAlphabet |
Constructor Summary | |
PlayfairKey()
|
Method Summary | |
int |
findCharPosition(char ch)
Returns the position of the specified character. |
java.lang.String |
getAlgorithm()
Returns the algorithm name "Playfair". |
char |
getChar(int index)
Returns the character at the specified index. |
char |
getChar(int row,
int col)
Returns the character at the specified row and column. |
int |
getColIndex(int index)
Returns the column index for the specified index. |
int |
getLeftColIndex(int index)
Returns the left column index for the specified index. |
int |
getRightColIndex(int index)
Returns the right column index for the specified index. |
int |
getRowAboveIndex(int index)
Returns the row above the index for the specified index. |
int |
getRowBelowIndex(int index)
Returns the row below the index for the specified index. |
int |
getRowIndex(int index)
Returns the row index for the specified index. |
void |
init(java.lang.String keyspec)
Initializes the PlayfairKey with the specified keyspec. |
void |
printKeySquare()
Prints the playfair key to the System console. |
void |
testMethods()
Performs exhaustive tests of the methods that perform various indexing functions on the key. |
Methods inherited from class hcrypto.cipher.HistoricalKey |
getAlphabet, getBlocksize, getCiphAlphabet, getCTAlphabet, getInstance, getKeyDescriptorPrompt, getKeyword, getPlainAlphabet, initAlphabets, initKey, printAlphabets, removeDuplicateChars |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_KEY_DESCRIPTOR_PROMPT_STRING
public static final java.lang.String DEFAULT_KEYWORD_STRING
Constructor Detail |
public PlayfairKey()
Method Detail |
public void init(java.lang.String keyspec) throws java.lang.Exception
init
in class HistoricalKey
keySpec
- takes the form "keyword/alphabet", i.e. "ralph/az" for example,
which would be mapped into the instance variables keyword as a String
with the value of "ralph" and alphabet as a String with the value "az".public java.lang.String getAlgorithm()
getAlgorithm
in class HistoricalKey
public int findCharPosition(char ch) throws java.lang.Exception
public char getChar(int index)
public char getChar(int row, int col)
public int getRowIndex(int index)
public int getColIndex(int index)
public int getRightColIndex(int index)
public int getLeftColIndex(int index)
public int getRowBelowIndex(int index)
public int getRowAboveIndex(int index)
public void testMethods()
public void printKeySquare()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |