|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecthcrypto.cipher.HistoricalKey
hcrypto.engines.PolySubstitutionKey
public class PolySubstitutionKey
Represents a key for a PolySubstitution cipher (which many authors call a Homophonic Substitution). The key is entirely represented by a keyword, which is inserted at the beginning of the decoding alphabet. More precisely, the cipher alphabet is likely to be considerably larger than the plaintext alphabet with certain plaintext characters mapped into several different ciphertext characters, that is, the encryption mapping is one-to-many. On the other hand, each ciphertext character represents a unique plaintext character. The keyword will be expanded to a string with length equal to the size of the cipher alphabet with all characters in the plaintext alphabet. The kth character of the cipher alphabet will be decoded into the kth character of the keyword. This map also uniquely determines the set of characters that each plaintext character can be mapped into.
The keyword provided by the user is expanded to length equal to the size of the cipher alphabet in the following manner. First a string is created of all plaintext characters not in the keyword and this string is added to the end of the keyword. If this would create a keyword longer than the size of the cipher alphabet, the keyword is truncated before adding the missing plaintext characters. On the other hand, if the keyword plus missing characters creates a new keyword with length less than the size of the cipher alphabet, copies of the new keyword are added to itself till it is longer than the size of the cipher alphabet before it is truncated to be exactly of length equal to the size of the cipher alphabet.
For example, suppose that the plaintext alphabet is a..z of size 26 and the cipher alphabet is a..zA..Z of size 52. Suppose the user chooses the keyword: "nowisthetimetolearncryptography" of length 31. The 10 characters "bdfjkquvxz" are not contained in this keyword so add them to the end of it. Now add the first 11 characters of the resulting keyword to the end of itself to get a new keyword of length 52. Thus we have the following table for decoding:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -- The cipher alphabet nowisthetimetolearncryptographybdfjkquvxznowisthetim -- The decoding alphabetThus for encryption, for example, "a" can be mapped into "q" or "B" and "t" can be mapped into any of the letters of "fimxUX" The PolySubstution cipher is one that requires that two different alphabets be used for the plaintext and ciphertext alphabets respectively. As just explained, the ciphertext alphabet must be larger than the plaintext alphabet. The following code segment provides an example of how to create and use a Polysubstitution cipher:
Cipher cipher = Cipher.getInstance("PolySubstitution");
HistoricalKey key = HistoricalKey.getInstance("PolySubstitution", cipher.getProvider());
key.init("nowisthetimetolearncryptography/az/azAZ");
cipher.init(key);
String c1encrypt = cipher.encrypt("this is a secret message");
In this case, the plaintext alphabet consists of the letters a..z, and
the ciphertext alphabet consists of the letters a..zA..Z. The decoding
alphabet would be constructed from the keyphrase as described above.
See also:
PolySubstitutionEngine
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. |
| Constructor Summary | |
|---|---|
PolySubstitutionKey()
|
|
| Method Summary | |
|---|---|
java.lang.String |
getAlgorithm()
Returns the algorithm name "PolySubstitution". |
java.lang.String[] |
getCodingAlphabet()
Returns the plaintext alphabet. |
char[] |
getDecodingAlphabet()
Returns the decoding alphabet. |
void |
init(java.lang.String keyspec)
Creates a PolySubstitutionKey with the specified keyspec. |
void |
init(java.lang.String keyword,
Alphabet alpha1,
Alphabet alpha2)
Initializes the PolySubstitutionKey given a keyword and one or more alphabets. |
void |
printAlphabets()
Prints both the cipher and plain alphabets to the System console. |
| Methods inherited from class hcrypto.cipher.HistoricalKey |
|---|
getAlphabet, getBlocksize, getCipherKey, getCTAlphabet, getInstance, getKeyDescriptorPrompt, getKeyword, getPlainKey, initKey, initKey, invertKey, removeDuplicateChars |
| Methods inherited from class java.lang.Object |
|---|
equals, 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 PolySubstitutionKey()
| Method Detail |
|---|
public void init(java.lang.String keyspec)
throws java.lang.Exception
init in class HistoricalKeykeySpec - takes the form "keyword/alphabet/cipheralphabet",
i.e. "nowisthetimetolearncryptography/az/azAZ" for example,
which would be mapped into the instance variables keyword
as a String with the value of "nowisthetimetolearncryptography",
alphabet as a String with the value "az" and
and cipheralphabet as a String with the value "azAZ".
java.lang.Exception
public void init(java.lang.String keyword,
Alphabet alpha1,
Alphabet alpha2)
throws java.lang.Exception
init in class HistoricalKeykeyword - -- a string version of the keywordalpha1, - alpha2 -- Alphabets for plain/ciphertext respectively. May
be identical.
java.lang.Exceptionpublic java.lang.String getAlgorithm()
getAlgorithm in class HistoricalKeypublic char[] getDecodingAlphabet()
public java.lang.String[] getCodingAlphabet()
public void printAlphabets()
printAlphabets in class HistoricalKey
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||