hcrypto.analyzer
Class CaesarAnalyzer

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

public class CaesarAnalyzer
extends CryptoAnalyzer
implements ExpertAnalyzer

Assumes that the text it is passed is encrypted with a Caesar shift. It performs a brute-force Chi-square analysis to determine the likely shift.


Field Summary
 
Fields inherited from class hcrypto.analyzer.CryptoAnalyzer
PERMUTATION, PLAYFAIR, RAILFENCE, SIMPLESUB
 
Fields inherited from interface hcrypto.analyzer.Analyzer
DECIPHER_LIMIT
 
Constructor Summary
CaesarAnalyzer()
           
CaesarAnalyzer(AnalyzerFrame f)
           
CaesarAnalyzer(TextStatistics ts)
           
 
Method Summary
 void doAnalysis()
          This method performs an analysis of the text assuming a Caesar (shift) cipher was used.
 void doAnalysis(java.lang.String text)
           
 java.lang.String getKeywordString()
           
 int getOptimalShift()
          This method performs a Chi-Square test to find the optimal shift.
 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 text)
          setup() initializes the text and the result string.
 java.lang.String toString()
          Every class should have a toString() method.
 
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

CaesarAnalyzer

public CaesarAnalyzer()

CaesarAnalyzer

public CaesarAnalyzer(AnalyzerFrame f)

CaesarAnalyzer

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

setup

public void setup(java.lang.String text)
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

getKeywordString

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

toString

public java.lang.String toString()
Description copied from class: CryptoAnalyzer
Every class should have a toString() method.

Overrides:
toString in class CryptoAnalyzer

doAnalysis

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

doAnalysis

public void doAnalysis()
This method performs an analysis of the text assuming a Caesar (shift) cipher was used. The goal is to find the shift (the Caesar key). It performs a Chi-square analysis on every possible shift to find the most likely shift.


getOptimalShift

public int getOptimalShift()
This method performs a Chi-Square test to find the optimal shift. This monoalphabetic version calls the more general polyalphabetic version, which computes a chi-square test on a text beginning with the first (0th) character and proceeding through each adjacent character.


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