Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
"Finish" phase 3 and project
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsingh87 committed Nov 27, 2023
1 parent 162ccc9 commit 2838dcf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 34 deletions.
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Frequency Analysis Simulator

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.
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.

## Methods of Cryptanalysis

* Frequency Analysis
* Kasiski Examination
* Freidman Test
Expand All @@ -12,7 +14,7 @@ The purpose of this project is to decrypt a monoalphabetic substitution cipher u
## Usage

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

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

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:
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:

```
outputs/
[ioc, friedman]_[kasiski, kerckhoff]/
Expand All @@ -37,54 +42,60 @@ outputs/

### Generate executable file

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:
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:

**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`
**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`

**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*
**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*

**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*
**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*

## Process


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

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

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

### Phase III

- [] Rewrite of simple substitution cipher (efficient and accurate, no dictionary)
- [] Visualization of data
- [] Data collection GUI
- [x] Variants of Vigenere cipher
* Data GUI
* Data collection GUI
* Variants of Vigenere cipher

### Phase II

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


### Phase I

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

## Concepts Used

* Advanced Data Structures - Java Collections API, including TreeSet, HashMap, ArrayList
* Layered Architecture - separated into presentation code (Java Swing framework), business logic (pure Java), and data analysis module (pure Java I/O)
* Layered Architecture - separated into presentation code (Java Swing framework), business logic (pure Java), and data
analysis module (pure Java I/O)
* Recursion

## Built With

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

## Sources of Research

* Inspiration from _The Code Book_ by Simon Singh
* _The Cryptanalyst_ by Helen Fouche Gaines
* Michigan Technological University - explanations of the Kasiski Examination and index of coincidence with working examples
* Michigan Technological University - explanations of the Kasiski Examination and index of coincidence with working
examples
5 changes: 5 additions & 0 deletions src/main/java/dataanalysis/DataCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import frequencyanalysissimulator.crypto.Vigenere;
import frequencyanalysissimulator.crypto.VigenereDecryption;

/**
* Outputs data table containing accuracy of the
* subsequences of a ciphertext encrypted from subsequences of a key of an input message
* to a CSV file in the outputs/ folder
*/
public class DataCollector {
private final static int PREFERRED_CIPHER_LENGTH = 1000;
private final static int PREFERRED_KEY_LENGTH = 20;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/dataanalysis/DataFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import java.nio.file.Files;
import java.nio.file.Path;

/**
* Utility class for reading files as Strings
*/
public class DataFileReader {
static String readInput(String id) throws IOException {
String expectedText = Files.readString(Path.of(String.format("data/inputs/%s.txt", id)));
return expectedText.replace(System.getProperty("line.separator"), " ");
}
static String readInput(String id) throws IOException {
String expectedText = Files.readString(Path.of(String.format("data/inputs/%s.txt", id)));
return expectedText.replace(System.getProperty("line.separator"), " ");
}
}
17 changes: 11 additions & 6 deletions src/main/java/dataanalysis/DataVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ public DataVisualizer() {
DataPopulater.main(new String[]{"all"});
setCount = 1;
trialCount = 'A';

File dataFile = new File("data/outputs/HARSHTRAITSHINEIMPORT/ioc_kerckhoff/1A.csv");
GraphPanel g = new GraphPanel(findAverages(dataFile));
add(g, BorderLayout.CENTER);
add(dataGroupControls(), BorderLayout.NORTH);
trialIdLabel = new JLabel(setCount + "" + trialCount);
trialIdLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(trialIdLabel, BorderLayout.SOUTH);
}

public static List<Double> findAverages(File dataFile) {
List<Double> averages = new ArrayList<>();
try (Scanner dataFileReader = new Scanner(dataFile)) {
dataFileReader.nextLine(); // Skip header
Expand All @@ -33,12 +43,7 @@ public DataVisualizer() {
} catch (IOException e) {
e.printStackTrace();
}
g = new GraphPanel(averages);
add(g, BorderLayout.CENTER);
add(dataGroupControls(), BorderLayout.NORTH);
trialIdLabel = new JLabel(setCount + "" + trialCount);
trialIdLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(trialIdLabel, BorderLayout.SOUTH);
return averages;
}

private void updateTrialIdLabel() {
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/dataanalysis/presentation/VigenereTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataanalysis.DataCollector;
import dataanalysis.DataFileReader;
import dataanalysis.DataVisualizer;
import frequencyanalysissimulator.crypto.CaesarDecryptionMethod;
import frequencyanalysissimulator.crypto.KeyLengthMethod;
import frequencyanalysissimulator.crypto.VigenereDecryption;
Expand Down Expand Up @@ -58,13 +59,15 @@ JComponent submission() {
private void collect(KeyLengthMethod keyLengthMethod, CaesarDecryptionMethod caesarDecryptionMethod) {
// Specific method for both steps (stopping case)
if (caesarDecryptionMethod != CaesarDecryptionMethod.ALL && keyLengthMethod != KeyLengthMethod.ALL) {
DataCollector.main(new String[]{
inputInfoMenu.getPlaintext(),
inputInfoMenu.getPlaintextId(),
keyLengthMethod.name(),
caesarDecryptionMethod.name(),
decryptParamsMenu.getKey()
});
new Thread(() -> {
DataCollector.main(new String[]{
inputInfoMenu.getPlaintext(),
inputInfoMenu.getPlaintextId(),
keyLengthMethod.name(),
caesarDecryptionMethod.name(),
decryptParamsMenu.getKey()
});
}).start();
} else if (keyLengthMethod == KeyLengthMethod.ALL) { // All key length methods
for (KeyLengthMethod method : KeyLengthMethod.values()) {
if (method != KeyLengthMethod.ALL) {
Expand Down

0 comments on commit 2838dcf

Please sign in to comment.