Skip to content

Commit 2838dcf

Browse files
committed
"Finish" phase 3 and project
1 parent 162ccc9 commit 2838dcf

File tree

5 files changed

+61
-34
lines changed

5 files changed

+61
-34
lines changed

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Frequency Analysis Simulator
22

3-
The purpose of this project is to decrypt a monoalphabetic substitution cipher using frequency analysis and find the optimal algorithm and conditions of decrypting a Vigenere cipher.
3+
The purpose of this project is to decrypt a monoalphabetic substitution cipher using frequency analysis and find the
4+
optimal algorithm and conditions of decrypting a Vigenere cipher.
45

56
## Methods of Cryptanalysis
7+
68
* Frequency Analysis
79
* Kasiski Examination
810
* Freidman Test
@@ -12,7 +14,7 @@ The purpose of this project is to decrypt a monoalphabetic substitution cipher u
1214
## Usage
1315

1416
1. Clone this repo with `git clone https://github.com/varunsingh87/Frequency-Analysis-Simulator`
15-
(for help see the [GitHub documentation](https://help.github.com/articles/cloning-a-repository/)).
17+
(for help see the [GitHub documentation](https://help.github.com/articles/cloning-a-repository/)).
1618
2. Run `mvn package`
1719
2. Run the GUI with the following command:
1820

@@ -28,7 +30,10 @@ Run the following command for data collection of a single input (~480 runs/data
2830
mvn compile exec:java -Dexec.mainClass="dataanalysis.DataCollector"
2931
```
3032

31-
Run the following command for data population of experiment data. To use a different key you will need to edit the default in DataCollector.java and make a new folder and subfolders of all the combinations of key length and caesar decryption algorithms in the following format:
33+
Run the following command for data population of experiment data. To use a different key you will need to edit the
34+
default in DataCollector.java and make a new folder and subfolders of all the combinations of key length and caesar
35+
decryption algorithms in the following format:
36+
3237
```
3338
outputs/
3439
[ioc, friedman]_[kasiski, kerckhoff]/
@@ -37,54 +42,60 @@ outputs/
3742

3843
### Generate executable file
3944

40-
To create an executable file without the user needing the Java Runtime Environment on his or her computer, use the `jpackage` utility from the Java Development Kit:
45+
To create an executable file without the user needing the Java Runtime Environment on his or her computer, use
46+
the `jpackage` utility from the Java Development Kit:
4147

42-
**Mac**: `jpackage --input target/ --name 'Frequency Analysis Simulation' --main-jar com.varunsingh.frequencyanalysissimulator-1.00.jar --main-class frequencyanalysissimulator.presentation.main.Main --type dmg --icon ./assets/icon.icns`
48+
**Mac
49+
**: `jpackage --input target/ --name 'Frequency Analysis Simulation' --main-jar com.varunsingh.frequencyanalysissimulator-1.00.jar --main-class frequencyanalysissimulator.presentation.main.Main --type dmg --icon ./assets/icon.icns`
4350

44-
**Windows**: `jpackage --input target/ --name 'Frequency Analysis Simulation' --main-jar com.varunsingh.frequencyanalysissimulator-1.00.jar --main-class frequencyanalysissimulator.presentation.main.Main --type exe --icon ./assets/icon.ico` *Does not work on Mac*
51+
**Windows
52+
**: `jpackage --input target/ --name 'Frequency Analysis Simulation' --main-jar com.varunsingh.frequencyanalysissimulator-1.00.jar --main-class frequencyanalysissimulator.presentation.main.Main --type exe --icon ./assets/icon.ico`
53+
*Does not work on Mac*
4554

46-
**Linux**: `jpackage --input target/ --name 'Frequency Analysis Simulation' --main-jar com.varunsingh.frequencyanalysissimulator-1.00.jar --main-class frequencyanalysissimulator.presentation.main.Main --type deb --icon ./assets/icon.ico` *Does not work on Mac*
55+
**Linux
56+
**: `jpackage --input target/ --name 'Frequency Analysis Simulation' --main-jar com.varunsingh.frequencyanalysissimulator-1.00.jar --main-class frequencyanalysissimulator.presentation.main.Main --type deb --icon ./assets/icon.ico`
57+
*Does not work on Mac*
4758

4859
## Process
4960

50-
5161
**Phase I: Monoalphabetic Ciphers**: July 22, 2019 - February 16, 2020
5262

5363
**Phase II: Vigenere Ciphers**: September 26, 2022 - May 8, 2023
5464

55-
**Phase III: Finishing Touches, Rewrites, Expansions**: July 22, 2023 - Present
65+
**Phase III: Graphics, Refactors, Variants**: July 22, 2023 - November 26, 2023
5666

5767
### Phase III
5868

59-
- [] Rewrite of simple substitution cipher (efficient and accurate, no dictionary)
60-
- [] Visualization of data
61-
- [] Data collection GUI
62-
- [x] Variants of Vigenere cipher
69+
* Data GUI
70+
* Data collection GUI
71+
* Variants of Vigenere cipher
6372

6473
### Phase II
6574

6675
* [Data from Phase II](https://docs.google.com/spreadsheets/d/e/2PACX-1vQIqW8qXtnbI1yTCQR_LcYpy6F7p6eZg5EP07no3c-lBoEkMUbpTPyxo_oa5mCCj7Gfk8LOTonOY-4a/pubhtml)
6776
* [Presentation](https://docs.google.com/presentation/d/e/2PACX-1vR5Vu_MXCbKyHm0vHaMW5Tn4qaJWVDV34Z_WX1WpHbejcwIzODNiuNKExOOTFTRUUDs7CPsYwz8PA1T/pub?start=false&loop=false&delayms=3000)
6877

69-
7078
### Phase I
7179

7280
* [Data from Phase I](https://docs.google.com/spreadsheets/d/130cqH1bGJPZ7mq2LrrTY6sMdm6E7qZP2Jea3s8cg3tA/edit#gid=0)
7381
* [Presentation](https://docs.google.com/presentation/d/e/2PACX-1vT29PD0nv69KI9cNDpZdsEA1p4eDg4P8V_XLVCWtpIFXDGnp_WmLrg-xiH120KWJkqppP9DZ-DlREr_/pub?start=false&loop=false&delayms=3000)
7482

7583
## Concepts Used
84+
7685
* Advanced Data Structures - Java Collections API, including TreeSet, HashMap, ArrayList
77-
* Layered Architecture - separated into presentation code (Java Swing framework), business logic (pure Java), and data analysis module (pure Java I/O)
86+
* Layered Architecture - separated into presentation code (Java Swing framework), business logic (pure Java), and data
87+
analysis module (pure Java I/O)
7888
* Recursion
7989

8090
## Built With
8191

8292
* [Java](https://www.java.com/en/) - The programming language
83-
* [Maven](https://maven.apache.org/) - The dependency management system
93+
* [Maven](https://maven.apache.org/) - The dependency management system
8494
* [JUnit](https://junit.org/junit5/) - The testing framework
8595

8696
## Sources of Research
8797

8898
* Inspiration from _The Code Book_ by Simon Singh
8999
* _The Cryptanalyst_ by Helen Fouche Gaines
90-
* Michigan Technological University - explanations of the Kasiski Examination and index of coincidence with working examples
100+
* Michigan Technological University - explanations of the Kasiski Examination and index of coincidence with working
101+
examples

src/main/java/dataanalysis/DataCollector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
import frequencyanalysissimulator.crypto.Vigenere;
1111
import frequencyanalysissimulator.crypto.VigenereDecryption;
1212

13+
/**
14+
* Outputs data table containing accuracy of the
15+
* subsequences of a ciphertext encrypted from subsequences of a key of an input message
16+
* to a CSV file in the outputs/ folder
17+
*/
1318
public class DataCollector {
1419
private final static int PREFERRED_CIPHER_LENGTH = 1000;
1520
private final static int PREFERRED_KEY_LENGTH = 20;

src/main/java/dataanalysis/DataFileReader.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import java.nio.file.Files;
55
import java.nio.file.Path;
66

7+
/**
8+
* Utility class for reading files as Strings
9+
*/
710
public class DataFileReader {
8-
static String readInput(String id) throws IOException {
9-
String expectedText = Files.readString(Path.of(String.format("data/inputs/%s.txt", id)));
10-
return expectedText.replace(System.getProperty("line.separator"), " ");
11-
}
11+
static String readInput(String id) throws IOException {
12+
String expectedText = Files.readString(Path.of(String.format("data/inputs/%s.txt", id)));
13+
return expectedText.replace(System.getProperty("line.separator"), " ");
14+
}
1215
}

src/main/java/dataanalysis/DataVisualizer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ public DataVisualizer() {
2121
DataPopulater.main(new String[]{"all"});
2222
setCount = 1;
2323
trialCount = 'A';
24+
2425
File dataFile = new File("data/outputs/HARSHTRAITSHINEIMPORT/ioc_kerckhoff/1A.csv");
26+
GraphPanel g = new GraphPanel(findAverages(dataFile));
27+
add(g, BorderLayout.CENTER);
28+
add(dataGroupControls(), BorderLayout.NORTH);
29+
trialIdLabel = new JLabel(setCount + "" + trialCount);
30+
trialIdLabel.setHorizontalAlignment(SwingConstants.CENTER);
31+
add(trialIdLabel, BorderLayout.SOUTH);
32+
}
33+
34+
public static List<Double> findAverages(File dataFile) {
2535
List<Double> averages = new ArrayList<>();
2636
try (Scanner dataFileReader = new Scanner(dataFile)) {
2737
dataFileReader.nextLine(); // Skip header
@@ -33,12 +43,7 @@ public DataVisualizer() {
3343
} catch (IOException e) {
3444
e.printStackTrace();
3545
}
36-
g = new GraphPanel(averages);
37-
add(g, BorderLayout.CENTER);
38-
add(dataGroupControls(), BorderLayout.NORTH);
39-
trialIdLabel = new JLabel(setCount + "" + trialCount);
40-
trialIdLabel.setHorizontalAlignment(SwingConstants.CENTER);
41-
add(trialIdLabel, BorderLayout.SOUTH);
46+
return averages;
4247
}
4348

4449
private void updateTrialIdLabel() {

src/main/java/dataanalysis/presentation/VigenereTab.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dataanalysis.DataCollector;
44
import dataanalysis.DataFileReader;
5+
import dataanalysis.DataVisualizer;
56
import frequencyanalysissimulator.crypto.CaesarDecryptionMethod;
67
import frequencyanalysissimulator.crypto.KeyLengthMethod;
78
import frequencyanalysissimulator.crypto.VigenereDecryption;
@@ -58,13 +59,15 @@ JComponent submission() {
5859
private void collect(KeyLengthMethod keyLengthMethod, CaesarDecryptionMethod caesarDecryptionMethod) {
5960
// Specific method for both steps (stopping case)
6061
if (caesarDecryptionMethod != CaesarDecryptionMethod.ALL && keyLengthMethod != KeyLengthMethod.ALL) {
61-
DataCollector.main(new String[]{
62-
inputInfoMenu.getPlaintext(),
63-
inputInfoMenu.getPlaintextId(),
64-
keyLengthMethod.name(),
65-
caesarDecryptionMethod.name(),
66-
decryptParamsMenu.getKey()
67-
});
62+
new Thread(() -> {
63+
DataCollector.main(new String[]{
64+
inputInfoMenu.getPlaintext(),
65+
inputInfoMenu.getPlaintextId(),
66+
keyLengthMethod.name(),
67+
caesarDecryptionMethod.name(),
68+
decryptParamsMenu.getKey()
69+
});
70+
}).start();
6871
} else if (keyLengthMethod == KeyLengthMethod.ALL) { // All key length methods
6972
for (KeyLengthMethod method : KeyLengthMethod.values()) {
7073
if (method != KeyLengthMethod.ALL) {

0 commit comments

Comments
 (0)