inital commit

This commit is contained in:
2020-10-18 21:50:38 +02:00
commit 9e03537284
32 changed files with 499 additions and 0 deletions

3
src/META-INF/MANIFEST.MF Normal file
View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: tech.loedige.Main

View File

@@ -0,0 +1,64 @@
package tech.loedige;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
public class Main {
public static void main(String[] args) {
// write your code here
char[][] code = generateCode();
outputCodeToConsole(code);
outputCodeToScreen(code);
}
private static void outputCodeToScreen(char[][] code) {
JFrame frame = new JFrame();
Container container = frame.getContentPane();
for(int i = 0; i<code[0].length;i++){
container.add(new JLabel((code[0][i]+" >> " + code[1][i])));
}
JButton rerunButton = new JButton("Neue Verschlüsselung");
rerunButton.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
outputCodeToScreen(generateCode());
}
});
container.add(rerunButton);
frame.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
frame.pack();
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
Point centerPoint = graphicsEnvironment.getCenterPoint();
frame.setLocation(centerPoint.x/4, centerPoint.y/4);
frame.setVisible(true);
}
public static char[][] generateCode(){
char[][] code = new char[2][26];
code[0] = new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
code[1] = new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
Random rand = new Random();
for (int i = 0; i < code[1].length; i++) {
int randomIndexToSwap = rand.nextInt(code[1].length);
char temp = code[1][randomIndexToSwap];
code[1][randomIndexToSwap] = code[1][i];
code[1][i] = temp;
}
return code;
}
public static void outputCodeToConsole(char[][] code){
for(int r=0; r<code[0].length;r++){
System.out.println(code[0][r] + "\t->\t"+code[1][r]);
}
}
}