|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecthcrypto.analyzer.CryptoAnalyzer
hcrypto.analyzer.DigramAnalyzer
public class DigramAnalyzer
Analyzes traditional cryptograms of the sort you find in the newspaper. It assumes the text is a word-delimited cryptogram created using a simple substitution cipher.
Credits: The algorithm here is based on the algorithm reported by Thomas Jakobsen, A fast method for the cryptanalysis of substitution ciphers. in Cryptologia, Volume 19, Issue 3 July 1995 , pages 265 - 274.
At present this analyzer only works for the alphabet 'a' to 'z'.
The algorithm computes a digram distribution matrices, that are used to compare the distribution of digram frequencies in the cryptogram with their distribution in standard English text (as computed from a book, such as Tom Sawyer). Cryptanalysis proceeds by generating an initial key and then computing how close to a correct decryption it comes. However, rather than using the key to decrypt the cryptogram, the algorithm simply compares the distribution matrices. This results in a much faster algorithm.
The fitness function, in this case, is the sum of the numerical differences between the frequencies of the English and crypto matrices. The closer to 0, the better the fit.
The algorithm
Speedup. This algorithm can be sped up by noticing that swapping a and b in the key would result in swapping columns a and b and then rows a and b in the cryptograms digram distribution matrix. The speedup is due to the fact that the crypto text needs to be parsed only once.
Swapping strategy. Although the algorithm will work for random a and b, it uses a more intelligent strategy -- namely, swap letters whose frequencies are close together in the cryptogram. This can be done by letting S represent a vector of ciphertext symbols ranked in order from highest to lowest, so S1 probably probably represents the space, S2, the letter 'e' and so forth.
The swapping strategy goes as follows: S1/S2, S2/S3,...,S26/S27. Then S1/S3, S2/S4, ...,S25/S27, and so on.
| Field Summary |
|---|
| Fields inherited from class hcrypto.analyzer.CryptoAnalyzer |
|---|
PERMUTATION, PLAYFAIR, RAILFENCE, SIMPLESUB |
| Fields inherited from interface hcrypto.analyzer.Analyzer |
|---|
DECIPHER_LIMIT |
| Constructor Summary | |
|---|---|
DigramAnalyzer()
|
|
DigramAnalyzer(AnalyzerFrame f)
|
|
DigramAnalyzer(TextStatistics ts)
|
|
| Method Summary | |
|---|---|
java.lang.String |
decrypt(boolean replace_brace)
Applies the current key, d_key, to the cryptogram itself. |
void |
doAnalysis()
This method performs an analysis of the text using the algorithm described above. |
java.lang.String |
getReport()
This method is part of the Analyzer interface. |
void |
run()
This method is part of the Analyzer interface. |
void |
setup(java.lang.String text)
This method initializes the Analyzer. |
java.lang.String |
toString()
This method returns the report generated by the analysis. |
| Methods inherited from class hcrypto.analyzer.CryptoAnalyzer |
|---|
prettyPrint, setup, stopThread, threadIsStopped |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DigramAnalyzer()
public DigramAnalyzer(AnalyzerFrame f)
public DigramAnalyzer(TextStatistics ts)
throws java.lang.NullPointerException
java.lang.NullPointerException| Method Detail |
|---|
public void setup(java.lang.String text)
setup in interface Analyzersetup in class CryptoAnalyzertext - a String pointing to the text being analyzedpublic void run()
run in interface Analyzerrun in interface java.lang.Runnablerun in class CryptoAnalyzerpublic java.lang.String getReport()
getReport in interface AnalyzergetReport in class CryptoAnalyzerpublic java.lang.String toString()
toString in class CryptoAnalyzerpublic java.lang.String decrypt(boolean replace_brace)
replace_brace - true if you want to replace } with a blank
public void doAnalysis()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||