|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecthcrypto.cipher.CipherEngine
hcrypto.cipher.BlockCipher
hcrypto.engines.PolySubstitutionEngine
public class PolySubstitutionEngine
Implements a PolySubstitution cipher algorithm (which many authors call a Homophonic Substitution cipher). The key is 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 encoding algorithm maintains a variable that, for each character in the plaintext message, stores the position of that character. The value of that variable modulo the number of ciphertext characters that plaintext character can be mapped into determines which ciphertext character it is mapped into.
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 alphabetif (args[0].indexOf('/') != -1) { cipherName = args[0].substring(0,args[0].indexOf('/')); providerName = args[0].substring(args[0].indexOf('/')+1); } else { cipherName = args[0]; providerName = "Default"; } String keyspec = args[1]; // Create an instance of the cipher and its corresponding key Cipher cipher = Cipher.getInstance(cipherName, providerName); HistoricalKey key = HistoricalKey Thus for encryption, for example, "a" can be mapped into "q" or "B" and "t" can be mapped into any of the letters of "fimxUX". If the plaintext message starts with the word "that", the first "t" of "that" would be encoded as "f", the second would be encoded as "i", and so on. Since there are six different encodings for "t", after six encodings, the seventh occurrence of 't' would be encoded as "f". 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:
PolySubstitutionKey
Alphabet
| Constructor Summary | |
|---|---|
PolySubstitutionEngine()
Creates a PolySubstitutionEngine and sets the alphabetRangeOptions instance variable to "111111", which translates to all six alphabet options. |
|
| Method Summary | |
|---|---|
java.lang.String |
engineDecode(java.lang.String s)
Returns an decoded String for the specified encode String. |
java.lang.String |
engineEncode(java.lang.String s)
Returns an encoded String for the specified String. |
| Methods inherited from class hcrypto.cipher.CipherEngine |
|---|
getAlphabetRangeOptions |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PolySubstitutionEngine()
| Method Detail |
|---|
public java.lang.String engineEncode(java.lang.String s)
throws java.lang.Exception
s - the String to be encoded
java.lang.Exception
public java.lang.String engineDecode(java.lang.String s)
throws java.lang.Exception
s - the String to be decoded.
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||