hcrypto.analyzer
Class VigenereAnalyzer

java.lang.Object
  extended by hcrypto.analyzer.CryptoAnalyzer
      extended by hcrypto.analyzer.VigenereAnalyzer
All Implemented Interfaces:
Analyzer, ExpertAnalyzer, java.lang.Runnable

public class VigenereAnalyzer
extends CryptoAnalyzer
implements ExpertAnalyzer

Assumes that the text it is passed is encrypted with a Vigenere cipher. It performs both the Kasiski Test and the Superposition Analysis.


Field Summary
static int MAX_BIGRAMS
           
static int MAX_CONTACT
           
static int MAX_FACTORS
           
static int MAX_KEYWORD
           
static double SUPERPOSNUMBER
           
 
Fields inherited from class hcrypto.analyzer.CryptoAnalyzer
PERMUTATION, PLAYFAIR, RAILFENCE, SIMPLESUB
 
Fields inherited from interface hcrypto.analyzer.Analyzer
DECIPHER_LIMIT
 
Constructor Summary
VigenereAnalyzer()
           
VigenereAnalyzer(AnalyzerFrame f)
           
VigenereAnalyzer(TextStatistics ts)
           
 
Method Summary
 void computeBigramDistances(java.lang.String s)
           
 void computeSuperpositionAnalysis(java.lang.String s)
          This method performs a superposition test.
 void doAnalysis()
           
 void doAnalysis(java.lang.String s)
           
 java.lang.String estimateKeyword(int keyLen)
          To find the find the keyword we break the cryptogram into keyLen monoalphabetic cryptograms, each of which is obtained by a Caesar shift from the standard alphabet.
 int estimateKeywordLength(int[] factors)
           
 java.lang.String getKeywordString()
           
 int getOptimalShift(int firstChar, int displ)
          This method performs a Chi-Square test to find the optimal Caesar shift on a polyalphabetic text.
 java.lang.String getReport()
          Part of Analyzer interface.
 void run()
          Part of Analyzer and Runnable interface.
 void setup(java.lang.String s)
          setup() initializes the text and the result string.
 
Methods inherited from class hcrypto.analyzer.CryptoAnalyzer
prettyPrint, setup, stopThread, threadIsStopped, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_BIGRAMS

public static final int MAX_BIGRAMS
See Also:
Constant Field Values

MAX_FACTORS

public static final int MAX_FACTORS
See Also:
Constant Field Values

MAX_KEYWORD

public static final int MAX_KEYWORD
See Also:
Constant Field Values

MAX_CONTACT

public static final int MAX_CONTACT
See Also:
Constant Field Values

SUPERPOSNUMBER

public static final double SUPERPOSNUMBER
See Also:
Constant Field Values
Constructor Detail

VigenereAnalyzer

public VigenereAnalyzer()

VigenereAnalyzer

public VigenereAnalyzer(AnalyzerFrame f)

VigenereAnalyzer

public VigenereAnalyzer(TextStatistics ts)
                 throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException
Method Detail

setup

public void setup(java.lang.String s)
Description copied from class: CryptoAnalyzer
setup() initializes the text and the result string. Note that for files containing test cryptograms, the solution is sometimes also provided following the $$$ marker.

Specified by:
setup in interface Analyzer
Overrides:
setup in class CryptoAnalyzer

run

public void run()
Description copied from class: CryptoAnalyzer
Part of Analyzer and Runnable interface. Override this method in the subclass.

Specified by:
run in interface Analyzer
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class CryptoAnalyzer

getReport

public java.lang.String getReport()
Description copied from class: CryptoAnalyzer
Part of Analyzer interface.

Specified by:
getReport in interface Analyzer
Overrides:
getReport in class CryptoAnalyzer

computeSuperpositionAnalysis

public void computeSuperpositionAnalysis(java.lang.String s)
This method performs a superposition test. It places the original text on one line and superposes a copy of the text, displaced by 1..MAX_KEYWORD positions, under the original text. Then it computes the number of coincidences that result between the two lines.


computeBigramDistances

public void computeBigramDistances(java.lang.String s)

getKeywordString

public java.lang.String getKeywordString()
Specified by:
getKeywordString in interface ExpertAnalyzer

doAnalysis

public void doAnalysis(java.lang.String s)
Specified by:
doAnalysis in interface ExpertAnalyzer

doAnalysis

public void doAnalysis()

estimateKeywordLength

public int estimateKeywordLength(int[] factors)

estimateKeyword

public java.lang.String estimateKeyword(int keyLen)
To find the find the keyword we break the cryptogram into keyLen monoalphabetic cryptograms, each of which is obtained by a Caesar shift from the standard alphabet. So for each letter in the keyword, find its shift.


getOptimalShift

public int getOptimalShift(int firstChar,
                           int displ)
This method performs a Chi-Square test to find the optimal Caesar shift on a polyalphabetic text. It assumes that every _displ_ character starting at _firstChar_ belongs to the same alphabet. It is used primarily for analyzing Vigenere-like and Caesar-shift cryptograms.

Parameters:
firstChar - - the location of the first character in the cryptotext
displ - - the displacement (keyword length) or cycle length