/** * File: SubstitutionAnalysis.java * @author A.Kurd * * Description: Implements a Java 1.1 version of a GUI tool for the final ouput of this program. It displays * the most likely key, listed 'a' to 'z', the number of bigram hits (matches) and trigram hits. * Credits: This program is modelled after the frequency test of the CryptoToolJ program by Ralph Morelli. * * Copyright: This program is in the public domain. You can do whatever you want with * it as long as I get credit for my work and as long as you offer your changes to me * so I can possible add them to the "official" version. */ package analyzers; // Analyzer plugins belong to this package import hcrypto.analyzer.*; // This is where Analyzer is import java.awt.TextArea; import hcrypto.cipher.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.*; public class SubstitutionAnalysis extends Frame implements Analyzer{ public Frame frame[] = new Frame[10]; //the frames that the top 10 KeyGroups are displayed public KeyBuilder kb= new KeyBuilder(); //to count letter frequency public Calculate ct = new Calculate(); //to score the different KeyGroups public BigramCount bc= new BigramCount(); //to collect Bigram data public TrigramCount tc = new TrigramCount(); //to collect Trigram data public KeyGroups kg = new KeyGroups(); //to create possible KeyGroups public String output [] = new String [10]; //The 10 strings were the output is collected public int result [] = new int[128]; //array to collect the order of letters for the KeyGroup public int TriFreq[][] = new int[128][3]; //used to store the Trigram by frequency because originally stoared as chars and need ints public int resultKey [] = new int[128]; //Final Key stored in the array public int random1[] = {1,2,3,4,5,6,7,8}; //numbers to create the key for groups 2 thru 5 public int random2[] = {1,2}; public int random3[] = {1,2,3,4,5,6,7,8,9}; public int random4[] = {1,2,3}; private TextArea text1; // Pointers to the text to be analyzed private TextArea display1; // And the window where results are displayed public TextArea display [] = new TextArea[10]; //TextAreas for displaying the keys public char freqI [] = {'e','t', 'a', 'o', 'i', 'n', 's', 'h', 'r', 'd', 'l', 'c', 'u', 'm', 'w', 'f', 'g', 'y', 'p', 'b','v', 'k', 'j', 'x', 'q', 'z'};//list of letters by frequency public int total [] = new int [10]; //scores for the KeyGroup public int rating [][] = new int [10][3]; //ratings for the Keys int l = 0; public void SubstitutionAnalysis(String text){ }//BigramDisplay //necessary for the analysis package public void setup(TextArea text1, TextArea display1) { this.text1 = text1; this.display1 = display1; }//setup /*First method called by the class. Tells the user they have called this method. Collects data on letter frequency, bigram frequency and trigram frequency. Changes the chars for Trigram data into ints, rather than chars for use later. This recreates the keys the possible keys and rescores them. It then finds the highest scoring key and displays it for the user.*/ public void run() { display1.append("Substitution Analysis activated" + "\n"); int n = 1; kb.count(text1.getText()); bc.count(text1.getText()); tc.count(text1.getText()); for(int i=0; i<12; i++) if(tc.frequencies[i] != null){ TriFreq[i][0] = (int)tc.frequencies[i][0]; TriFreq[i][1] = (int)tc.frequencies[i][1]; TriFreq[i][2] = (int)tc.frequencies[i][2];}//if for( int i = 0; i<10; i++){ create(i); score(i,result);}//for int k = total[0]; for(int j = 1; j<10; j++){ if(k greatest){ greatest = r[i][0]; biHits = r[i][1]; triHits = r[i][2]; position = i;}//if }//for display1.append("Value: " + greatest + " for Key" + (position+1) + " with " + biHits + " bigram hits and " + triHits + " trigram hits.\n"); display1.append("The most accurate key, listed from a to z, is: \n"); int high = rating[0][0]; int place = 0; for(int i=1; i<10; i++) if(rating[i][0] !=0) if(rating[i][0]>high){high=rating[i][0]; place=i;}//if create(1); createKey(result, place); //build(result); display1.append((char)resultKey[2]+ "" + ", " +(char)resultKey[19]+ "" + ", " +(char)resultKey[11]+ "" + ", " +(char)resultKey[9]+ "" + ", " + (char)resultKey[0]+ "" + ", " +(char)resultKey[15]+ "" + ", " +(char)resultKey[16]+ "" + ", " +(char)resultKey[7]+ "" + ", " +(char)resultKey[4]+ "" + ", " + (char)resultKey[22]+ "" + ", " +(char)resultKey[21]+ "" + ", " +(char)resultKey[10]+ "" + ", " +(char)resultKey[13]+ "" + ", " +(char)resultKey[5]+ "" + ", " + (char)resultKey[3]+ "" + ", " +(char)resultKey[18]+ "" + ", " +(char)resultKey[24]+ "" + ", " +(char)resultKey[8]+ "" + ", " +(char)resultKey[6]+ "" + ", " + (char)resultKey[1]+ "" + ", " +(char)resultKey[12]+ "" + ", " +(char)resultKey[20]+ "" + ", " +(char)resultKey[14]+ "" + ", " +(char)resultKey[23]+ "" + ", " + (char)resultKey[17]+ "" + ", " +(char)resultKey[25]+ "" + "\n"); }//probable /*This method creates the possible KeyGroups and the scores them below*/ public int[] create(int i){ if(i == 0){ for(int k = 0; k