hcrypto.analyzer
Class AffineAnalyzer

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

public class AffineAnalyzer
extends CryptoAnalyzer
implements ExpertAnalyzer

Description: This class assumes that the text it is passed is encrypted with an Affine engine.


Field Summary
 
Fields inherited from class hcrypto.analyzer.CryptoAnalyzer
PERMUTATION, PLAYFAIR, RAILFENCE, SIMPLESUB
 
Fields inherited from interface hcrypto.analyzer.Analyzer
DECIPHER_LIMIT
 
Constructor Summary
AffineAnalyzer()
           
AffineAnalyzer(AnalyzerFrame f)
           
AffineAnalyzer(TextStatistics ts)
           
 
Method Summary
 void doAnalysis()
          This method prints an analysis of the text assuming a Affine (linear) cipher was used.
 void doAnalysis(java.lang.String text)
           
 double getChiSquare(java.lang.String text)
           
 java.lang.String getKeywordString()
           
 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

AffineAnalyzer

public AffineAnalyzer()

AffineAnalyzer

public AffineAnalyzer(AnalyzerFrame f)

AffineAnalyzer

public AffineAnalyzer(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 prints an analysis of the text assuming a Affine (linear) cipher was used. The goal is to find the values of A and B in y = Ax + B. If we assume an alphabet of a..z, then A can take on the values 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25. These are the values for which gcd(A, 26) = 1. B can take on the values 0..25. So there are 12 x 26 = 312 possible keys. This method does an exhaustive search of these keys using Chi-square test to identify the optimum key.


getChiSquare

public double getChiSquare(java.lang.String text)