Skip to content

Commit

Permalink
Part of CryptoTool added
Browse files Browse the repository at this point in the history
  • Loading branch information
mipet23 committed Feb 7, 2022
1 parent 2fd848f commit 7a7d9af
Show file tree
Hide file tree
Showing 60 changed files with 1,949 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/kryptojagd/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void start(Stage stage) {

Parent root;
try {

root = FXMLLoader.load(getClass().getResource("presentation/Startfenster.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("css/startwindow.css").toExternalForm());
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/kryptojagd/controls/StartWindowController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.kryptojagd.controls;

import java.io.IOException;

import org.kryptojagd.cryptotools.CryptoTool;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.stage.Stage;

/**
* Controller for the Launch Window
Expand Down Expand Up @@ -75,4 +80,24 @@ void clickCryptoVigeniere(ActionEvent event) {
System.out.println("Es wurde auf Kryptotool Vigeniére Button geklickt!");
mainController.startLevel();
}

@FXML
void caesar(ActionEvent event) {
try {
CryptoTool.caesar(new Stage());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@FXML
void vigenere(ActionEvent event) {
try {
CryptoTool.vigenere(new Stage());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
108 changes: 108 additions & 0 deletions src/main/java/org/kryptojagd/cryptotools/CryptoTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.kryptojagd.cryptotools;

import java.io.IOException;
import java.util.HashMap;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class CryptoTool extends Application {

@Override public void start(Stage stage) throws IOException {

// haeufigkeitsanalyse(stage);
vigenere(stage);
//karski(stage);

}

public static void main(String[] args) {
launch(args);
//FrequencyAnalysis f = new FrequencyAnalysis();
// f.initialize();
}

public static void caesar(Stage stage) throws IOException {
stage.setResizable(false);
stage.setTitle("Häufigkeitsanalyse");

String testText = "EJFT JTU FJO CFJTQJFMUFYU EFS NJU FJOFN LMJDL WFSTDIMÜTTFMU XFSEFO LBOO. "
+ "IJFS LBOO BVDI FJO FJHFOFO UFYU IFSFJO HFTDISJFCFO, PEFS FJO HFIFJNDPEF AVN "
+ "FOUTDIMÜTTFMO IFSFJO LPQJFSU XFSEFO.";


FrequencyAnalysisController.setText(testText);
//FrequencyAnalysisController2.setText(testText);

// Parent root = FXMLLoader.load(getClass().getResource("vigenere.fxml"));
Parent root = FXMLLoader.load(CryptoTool.class.getResource("frequencyAnalysis.fxml"));
//Parent root = FXMLLoader.load(getClass().getResource("frequencyAnalysis2.fxml"));
Scene scene = new Scene(root);

// Scene scene = new Scene(bc,800,450);


stage.setScene(scene);
stage.show();

}

public static void vigenere(Stage stage) throws IOException {
stage.setResizable(false);
stage.setTitle("Häufigkeitsanalyse");

String testText = "EJFT JTU FJO CFJTQJFMUFYU EFS NJU FJOFN LMJDL WFSTDIMÜTTFMU XFSEFO LBOO. "
+ "IJFS LBOO BVDI FJO FJHFOFO UFYU IFSFJO HFTDISJFCFO, PEFS FJO HFIFJNDPEF ZVN "
+ "FOUTDIMÜTTFMO IFSFJO LPQJFSU XFSEFO.";


FrequencyAnalysisController.setText(testText);
//FrequencyAnalysisController2.setText(testText);

Parent root = FXMLLoader.load(CryptoTool.class.getResource("vigenere.fxml"));
//Parent root = FXMLLoader.load(getClass().getResource("frequencyAnalysis.fxml"));
//Parent root = FXMLLoader.load(getClass().getResource("frequencyAnalysis2.fxml"));
Scene scene = new Scene(root);

// Scene scene = new Scene(bc,800,450);


stage.setScene(scene);
stage.show();

}

public void karski(Stage stage) throws IOException {
stage.setResizable(false);
stage.setTitle("Häufigkeitsanalyse");

String testText = "EJFT JTU FJO CFJTQJFMUFYU EFS NJU FJOFN LMJDL WFSTDIMÜTTFMU XFSEFO LBOO. "
+ "IJFS LBOO BVDI FJO FJHFOFO UFYU IFSFJO HFTDISJFCFO, PEFS FJO HFIFJNDPEF ZVN "
+ "FOUTDIMÜTTFMO IFSFJO LPQJFSU XFSEFO.";


FrequencyAnalysisController.setText(testText);
//FrequencyAnalysisController2.setText(testText);

Parent root = FXMLLoader.load(getClass().getResource("karskiText.fxml"));
// Parent root = FXMLLoader.load(getClass().getResource("frequencyAnalysis.fxml"));
//Parent root = FXMLLoader.load(getClass().getResource("frequencyAnalysis2.fxml"));
Scene scene = new Scene(root);

// Scene scene = new Scene(bc,800,450);


stage.setScene(scene);
stage.show();

}
}
27 changes: 27 additions & 0 deletions src/main/java/org/kryptojagd/cryptotools/CustomBarChart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.kryptojagd.cryptotools;

import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.chart.Axis;
import javafx.scene.chart.BarChart;

public class CustomBarChart<X, Y> extends BarChart<X, Y> {

public CustomBarChart(Axis<X> xAxis, Axis<Y> yAxis) {
super(xAxis, yAxis);
// TODO Auto-generated constructor stub
// this.getPlotChildren();

}

@Override
public ObservableList<Node> getChartChildren() {
return super.getChartChildren();
}

@Override
public ObservableList<Node> getChildren() {
return super.getChildren();
}

}
88 changes: 88 additions & 0 deletions src/main/java/org/kryptojagd/cryptotools/FrequencyAnalysis.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.kryptojagd.cryptotools;

import java.util.HashMap;
import java.util.LinkedHashMap;

public class FrequencyAnalysis {


public static HashMap<String,Double> absoluteFrequency(String text) {

HashMap<String,Double> hashmap = new HashMap<String, Double>();
text = removeCharacters(text);

char c = 'A';
for (char letter = 'A'; letter <= 'Z'; letter++) {
hashmap.put(String.valueOf(letter), 0.0);
}

for (char letter : text.toCharArray()) {
double a = hashmap.get(String.valueOf(letter)) + 1.0;
hashmap.put(String.valueOf(letter), a);
}

return hashmap;
}

public static LinkedHashMap<String,Double> relativeFrequency(String text) {

LinkedHashMap<String,Double> hashmap = new LinkedHashMap<String, Double>();
text = removeCharacters(text);
double length = (double) text.length();

char c = 'A';
for (char letter = 'A'; letter <= 'Z'; letter++) {
hashmap.put(String.valueOf(letter), 0.0);
}

for (char letter : text.toCharArray()) {
double a = hashmap.get(String.valueOf(letter)) + (1 / length) * 100;
hashmap.put(String.valueOf(letter), a);
}

return hashmap;
}



public static LinkedHashMap<String, Double> germanLetterFrequency() {
LinkedHashMap<String,Double> germanLetterFrequency = new LinkedHashMap<String, Double>();

germanLetterFrequency.put("E", 17.4);
germanLetterFrequency.put("N", 9.78);
germanLetterFrequency.put("I", 7.55);
germanLetterFrequency.put("S", 7.27);
germanLetterFrequency.put("R", 7.0);
germanLetterFrequency.put("A", 6.51);
germanLetterFrequency.put("T", 6.15);
germanLetterFrequency.put("D", 5.08);
germanLetterFrequency.put("H", 4.76);
germanLetterFrequency.put("U", 4.35);
germanLetterFrequency.put("L", 3.44);
germanLetterFrequency.put("C", 3.06);
germanLetterFrequency.put("G", 3.01);
germanLetterFrequency.put("M", 2.53);
germanLetterFrequency.put("O", 2.51);
germanLetterFrequency.put("B", 1.89);
germanLetterFrequency.put("W", 1.89);
germanLetterFrequency.put("F", 1.66);
germanLetterFrequency.put("K", 1.21);
germanLetterFrequency.put("Z", 1.13);
germanLetterFrequency.put("P", 0.79);
germanLetterFrequency.put("V", 0.67);
// germanLetterFrequency.put("ß", 0.31);
germanLetterFrequency.put("J", 0.27);
germanLetterFrequency.put("Y", 0.04);
germanLetterFrequency.put("X", 0.03);
germanLetterFrequency.put("Q", 0.02);

return germanLetterFrequency;
}

private static String removeCharacters(String text) {

text = text.replaceAll("[^A-Z]", "");
return text;
}

}
Loading

0 comments on commit 7a7d9af

Please sign in to comment.