summaryrefslogtreecommitdiffstats
path: root/Master/Kryptografie/krypto1
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Kryptografie/krypto1')
-rw-r--r--Master/Kryptografie/krypto1/.classpath6
-rw-r--r--Master/Kryptografie/krypto1/.project19
-rw-r--r--Master/Kryptografie/krypto1/IntVerifier.java33
-rw-r--r--Master/Kryptografie/krypto1/KryptArith.java97
-rw-r--r--Master/Kryptografie/krypto1/KryptModel.java205
-rw-r--r--Master/Kryptografie/krypto1/KryptTool.java855
6 files changed, 1215 insertions, 0 deletions
diff --git a/Master/Kryptografie/krypto1/.classpath b/Master/Kryptografie/krypto1/.classpath
new file mode 100644
index 0000000..d736018
--- /dev/null
+++ b/Master/Kryptografie/krypto1/.classpath
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
diff --git a/Master/Kryptografie/krypto1/.project b/Master/Kryptografie/krypto1/.project
new file mode 100644
index 0000000..dcfc888
--- /dev/null
+++ b/Master/Kryptografie/krypto1/.project
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>krypto1</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
+ </natures>
+</projectDescription>
diff --git a/Master/Kryptografie/krypto1/IntVerifier.java b/Master/Kryptografie/krypto1/IntVerifier.java
new file mode 100644
index 0000000..db9baeb
--- /dev/null
+++ b/Master/Kryptografie/krypto1/IntVerifier.java
@@ -0,0 +1,33 @@
+import javax.swing.InputVerifier;
+import javax.swing.JComponent;
+import javax.swing.JTextField;
+import java.awt.Toolkit;
+
+/**
+ * @author Andreas Spirka, Sven Eisenhauer
+ * InputVerifier zur Überprüfung auf Integer-Werte
+ */
+public class IntVerifier extends InputVerifier {
+
+ /* (non-Javadoc)
+ * @see javax.swing.InputVerifier#verify(javax.swing.JComponent)
+ */
+ public boolean verify(JComponent arg0) {
+ boolean retVal=false;
+ JTextField tf = (JTextField) arg0;
+ String regexp = "[0-9]+";
+ retVal=tf.getText().matches(regexp);
+ if(!retVal)
+ {
+ Toolkit.getDefaultToolkit().beep();
+ }
+ return retVal;
+ }
+ /* (non-Javadoc)
+ * @see javax.swing.InputVerifier#shouldYieldFocus(javax.swing.JComponent)
+ */
+ public boolean shouldYieldFocus(JComponent input)
+ {
+ return verify(input);
+ }
+}
diff --git a/Master/Kryptografie/krypto1/KryptArith.java b/Master/Kryptografie/krypto1/KryptArith.java
new file mode 100644
index 0000000..d8faa16
--- /dev/null
+++ b/Master/Kryptografie/krypto1/KryptArith.java
@@ -0,0 +1,97 @@
+/**
+ *
+ */
+
+/**
+ * @author sven
+ *
+ */
+
+import java.math.*;
+import java.util.Random;
+
+public class KryptArith {
+ char bottomChar='~';
+ char topChar='!';
+ int bottomInt=(int) bottomChar;
+ int topInt=(int) topChar;
+
+ public BigInteger modInv(BigInteger a, BigInteger b)
+ {
+ BigInteger r1 = new BigInteger("0");
+ BigInteger r2 = new BigInteger("1");
+ BigInteger a_new = new BigInteger("0");
+ BigInteger b_new = new BigInteger("0");
+ BigInteger r1_new = BigInteger.ZERO;
+ BigInteger r2_new = BigInteger.ZERO;
+
+ while (b.compareTo(BigInteger.ONE) != 0)
+ {
+ a_new=b;
+ try
+ {
+ b_new=a.mod(b);
+ }
+ catch (Exception e)
+ {
+ System.out.println("No Inverse "+e);
+ //System.exit(1);
+ return BigInteger.ZERO.subtract(BigInteger.ONE);
+ }
+ r1_new = r2;
+ r2_new=r1.subtract(r2.multiply(a.divide(b)));
+ a=a_new;
+ b=b_new;
+ r1=r1_new;
+ r2=r2_new;
+ }
+ return r2;
+ }
+ public int modInv(int a, int b) throws Exception
+ {
+ int r1 = 1;
+ int r2 = 0;
+ int r1_new = 1;
+ int r2_new = 0;
+ int a_new = 0;
+ int b_new = 0;
+
+ while (b_new != 1)
+ {
+ a_new=b;
+ /*try
+ {
+ b_new=a % b;
+ }
+ catch (Exception e)
+ {
+ //System.out.println("No Inverse "+e);
+ //System.exit(1);
+ return -1;
+ }*/
+ b_new=a % b;
+ r1_new = r2;
+ r2_new = r1 - ((a / b) * r2);
+ a=a_new;
+ b=b_new;
+ r1=r1_new;
+ r2=r2_new;
+ }
+
+ return r2;
+ }
+ public int gcd(int a, int b)
+ {
+ if (b==0) return a;
+ return gcd(b,a%b);
+ }
+ public BigInteger gcd(BigInteger a, BigInteger b)
+ {
+ if (b.compareTo(BigInteger.ZERO) == 0) return a;
+ return gcd(b,a.mod(b));
+ }
+ public static int gen8bitPrim() {
+ Random rnd = new Random();
+ return BigInteger.probablePrime(8, rnd).intValue();
+ }
+}
diff --git a/Master/Kryptografie/krypto1/KryptModel.java b/Master/Kryptografie/krypto1/KryptModel.java
new file mode 100644
index 0000000..5027ff2
--- /dev/null
+++ b/Master/Kryptografie/krypto1/KryptModel.java
@@ -0,0 +1,205 @@
+import java.util.Observable;
+
+public class KryptModel extends Observable {
+ private int key_t;
+ private int key_s;
+ private int mod;
+ private char[][] knownPlain;
+ private String plain;
+ private String cipher;
+ private String method;
+ private int modInv;
+ private String status;
+
+ private KryptArith myKA=null;
+
+ public KryptModel() {
+ super();
+ setMethod("TAUSCH");
+ key_t=1;
+ key_s=1;
+ mod=1;
+ myKA=new KryptArith();
+ calcModInv();
+ plain="";
+ cipher="";
+ knownPlain=new char[2][2];
+ knownPlain[0][0]='1';
+ knownPlain[0][1]='1';
+ knownPlain[1][0]='1';
+ knownPlain[1][1]='1';
+ }
+ public int calcModInv()
+ {
+ try {
+ modInv=myKA.modInv(key_t, mod);
+ }
+ catch (Exception ae) {
+ status="Calculating mod. Inverse failed";
+ return 1;
+ }
+ status="Calculated mod. Inverse successfully";
+ setChanged();
+ notifyObservers();
+ return 0;
+ }
+
+ public void setkey_t(int t)
+ {
+ key_t=t;
+ status="key t set successfully";
+ setChanged();
+ notifyObservers();
+ }
+ public void setkey_s(int s)
+ {
+ key_s=s;
+ status="key s set successfully";
+ setChanged();
+ notifyObservers();
+ }
+ public void setmod(int m)
+ {
+ mod=m;
+ status="modulus m set successfully";
+ setChanged();
+ notifyObservers();
+ }
+ public void setPlain(String p)
+ {
+ plain=p.toLowerCase();
+ setChanged();
+ notifyObservers();
+ }
+ public void setCipher(String c)
+ {
+ cipher=c.toUpperCase();
+ setChanged();
+ notifyObservers();
+ }
+ public void setMethod(String m)
+ {
+ method=m;
+ setChanged();
+ notifyObservers();
+ }
+ public void setKnownPlain(char p1,char c1, char p2, char c2)
+ {
+ knownPlain[0][0]=p1;
+ knownPlain[1][0]=p2;
+ knownPlain[0][1]=c1;
+ knownPlain[1][1]=c2;
+ status="Known plaintext chars set. p1: "+
+ knownPlain[0][0]+" p2: "+
+ knownPlain[1][0]+" c1: "+
+ knownPlain[0][1]+" c2: "+
+ knownPlain[1][1];
+ setChanged();
+ notifyObservers();
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public int getkey_t()
+ {
+ return key_t;
+ }
+ public int getkey_s()
+ {
+ return key_s;
+ }
+ public int getmod()
+ {
+ return mod;
+ }
+ public int getModInv()
+ {
+ return modInv;
+ }
+ public String getplain()
+ {
+ return plain;
+ }
+ public String getcipher()
+ {
+ return cipher;
+ }
+ public void encrypt()
+ {
+ if (method.equals("TAUSCH"))
+ {
+ if ( plain.isEmpty() == false)
+ {
+ char[] temp=plain.toCharArray();
+ int tmp = 0;
+ for (int i=0;i<temp.length;i++)
+ {
+ tmp=(int)(temp[i]);
+ //tmp-=97;
+ tmp=((tmp + key_s) * key_t) % mod;
+ //tmp+=97;
+ temp[i]=(char)(tmp);
+ }
+ setCipher(new String(temp));
+ status="Encrypted successfully";
+ }
+ }
+ setChanged();
+ notifyObservers();
+ }
+ public void decrypt()
+ {
+ if (method.equals("TAUSCH"))
+ {
+ if ( cipher.isEmpty() == false)
+ {
+ char[] temp=cipher.toLowerCase().toCharArray();
+ int tmp = 0;
+ for (int i=0;i<temp.length;i++)
+ {
+ tmp=(int)(temp[i]);
+ //tmp-=97;
+ tmp= (tmp*modInv - key_s ) % mod;
+ //tmp+=97;
+ temp[i]=(char)(tmp);
+ }
+ setPlain(new String(temp));
+ status="Decrypted successfully";
+ }
+ }
+ setChanged();
+ notifyObservers();
+ }
+ public void attack() {
+ char p1=knownPlain[0][0];
+ char p2=knownPlain[1][0];
+ char c1=knownPlain[0][1];
+ char c2=knownPlain[1][1];
+ /*
+ int ci1,ci2,pi1,pi2;
+
+ ci1=((int)c1);
+ ci2=((int)c2);
+ pi1=((int)p1);
+ pi2=((int)p2);
+ */
+ try {
+ key_t=( (c1-c2) * myKA.modInv(p1-p2,mod) )%mod;
+ key_s = ( ( c1 * myKA.modInv(key_t,mod) ) - p1 ) % mod;
+ status="Keys found";
+ }
+ catch (Exception e) {
+ status="Could not find keys";
+ }
+ setChanged();
+ notifyObservers();
+ }
+ public void genMod() {
+ setmod(KryptArith.gen8bitPrim());
+ status="Prime successfully generated";
+ setChanged();
+ notifyObservers();
+ }
+}
diff --git a/Master/Kryptografie/krypto1/KryptTool.java b/Master/Kryptografie/krypto1/KryptTool.java
new file mode 100644
index 0000000..8788fec
--- /dev/null
+++ b/Master/Kryptografie/krypto1/KryptTool.java
@@ -0,0 +1,855 @@
+import java.awt.BorderLayout;
+import javax.swing.JPanel;
+import javax.swing.JFrame;
+import javax.swing.JInternalFrame;
+import javax.swing.JMenuBar;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JLabel;
+import java.awt.GridBagLayout;
+import javax.swing.JButton;
+import java.awt.GridBagConstraints;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import java.awt.Dimension;
+import javax.swing.JList;
+import java.awt.event.*;
+import java.util.Observer;
+import java.util.Observable;
+import javax.swing.JRadioButton;
+import javax.swing.*;
+import java.awt.GridLayout;
+import java.awt.CardLayout;
+import java.awt.Insets;
+import java.awt.Rectangle;
+
+public class KryptTool extends JFrame implements Observer,WindowListener {
+
+ KryptModel myKM = new KryptModel(); // @jve:decl-index=0:
+ KryptArith myKA = new KryptArith();
+
+ private static final long serialVersionUID = 1L;
+
+ private JPanel jContentPane = null;
+
+ private JMenuBar jJMenuBar = null;
+
+ private JMenu jMenu = null;
+
+ private JMenuItem jMenuItem = null;
+
+ private JPanel jPanel = null;
+
+ private JButton jButton = null;
+
+ private JButton jButton1 = null;
+
+ private JLabel jLabel = null;
+
+ private JTextArea jTextArea = null;
+
+ private JPanel jPanel1 = null;
+
+ private JLabel jLabel1 = null;
+
+ private JButton jButton2 = null;
+
+ private JButton jButton3 = null;
+
+ private JTextArea jTextArea1 = null;
+
+ private JPanel jPanel2 = null;
+
+ private JButton jButton4 = null;
+
+ private JButton jButton5 = null;
+
+ private JButton jButton6 = null;
+
+ private JLabel jLabel2 = null;
+
+ private JLabel jLabel3 = null;
+
+ private JTextField jTextField = null;
+
+ private JLabel jLabel4 = null;
+
+ private JTextField jTextField1 = null;
+
+ private JLabel jLabel5 = null;
+
+ private JTextField jTextField2 = null;
+
+ private JLabel jLabel6 = null;
+
+ private JLabel jLabel7 = null;
+
+ private JLabel jLabel8 = null;
+
+ private JLabel jLabel9 = null;
+
+ private JLabel jLabel10 = null;
+
+ private JLabel jLabel11 = null;
+
+ private JTextField jTextField3 = null;
+
+ private JTextField jTextField4 = null;
+
+ private JTextField jTextField5 = null;
+
+ private JTextField jTextField6 = null;
+
+ private JButton jButton7 = null;
+ private JRadioButton jRadioButton = null;
+ private JLabel jLabel12 = null;
+ private JRadioButton jRadioButton1 = null;
+ private ButtonGroup bg = null;
+ private JPanel jPanel4 = null;
+ private JLabel jLabel14 = null;
+ private JLabel jLabel15 = null;
+ private JLabel jLabel16 = null;
+ private JLabel jLabel17 = null;
+ private JButton jButton8 = null;
+ private JPanel jPanel5 = null;
+ private JButton jButton9 = null;
+ private JLabel jLabel13 = null;
+ //private Dimension tfDim=null;
+ /**
+ * This is the default constructor
+ */
+ public KryptTool() {
+ super();
+ initialize();
+ }
+
+ public void update(Observable o, Object arg) {
+ //System.out.println("myKM updated");
+ jTextField.setText(Integer.toString(myKM.getkey_t()));
+ jTextField1.setText(Integer.toString(myKM.getkey_s()));
+ jTextField2.setText(Integer.toString(myKM.getmod()));
+ jTextArea.setText(myKM.getplain());
+ jTextArea1.setText(myKM.getcipher());
+ //myKM.calcModInv();
+ jLabel17.setText(Integer.toString(myKM.getModInv()));
+ jLabel15.setText(myKM.getStatus());
+ }
+ public void windowClosing(WindowEvent e) {
+ exitKT();
+ }
+ public void windowClosed(WindowEvent e) {
+ }
+ public void windowOpened(WindowEvent e) {
+ }
+ public void windowIconified(WindowEvent e) {
+ }
+ public void windowDeiconified(WindowEvent e) {
+ }
+ public void windowActivated(WindowEvent e) {
+ }
+ public void windowDeactivated(WindowEvent e) {
+ }
+ public void windowGainedFocus(WindowEvent e) {
+ }
+ public void windowLostFocus(WindowEvent e) {
+ }
+ public void windowStateChanged(WindowEvent e) {
+ }
+
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize() {
+ //tfDim = new Dimension(20,60);
+ this.setSize(760, 462);
+ this.setJMenuBar(getJJMenuBar());
+ this.setContentPane(getJContentPane());
+ this.setTitle("KryptTool");
+ myKM.addObserver(this);
+ }
+
+ /**
+ * This method initializes jContentPane
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJContentPane() {
+ if (jContentPane == null) {
+ GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
+ gridBagConstraints18.gridx = 0;
+ gridBagConstraints18.ipady = 318;
+ gridBagConstraints18.gridy = 1;
+ GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
+ gridBagConstraints17.gridx = 2;
+ gridBagConstraints17.ipady = 308;
+ gridBagConstraints17.gridy = 1;
+ GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
+ gridBagConstraints16.gridx = 1;
+ gridBagConstraints16.ipadx = 133;
+ gridBagConstraints16.ipady = 348;
+ gridBagConstraints16.gridy = 1;
+ GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
+ gridBagConstraints15.gridwidth = 3;
+ gridBagConstraints15.gridy = 2;
+ gridBagConstraints15.ipadx = 658;
+ gridBagConstraints15.gridx = 0;
+ GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
+ gridBagConstraints14.gridwidth = 3;
+ gridBagConstraints14.gridy = 0;
+ gridBagConstraints14.ipadx = -1295;
+ gridBagConstraints14.gridx = 0;
+ jContentPane = new JPanel();
+ jContentPane.setLayout(new GridBagLayout());
+ jContentPane.add(getJPanel2(), gridBagConstraints14);
+ jContentPane.add(getJPanel4(), gridBagConstraints15);
+ jContentPane.add(getJPanel5(), gridBagConstraints16);
+ jContentPane.add(getJPanel(), gridBagConstraints17);
+ jContentPane.add(getJPanel1(), gridBagConstraints18);
+ }
+ return jContentPane;
+ }
+
+ /**
+ * This method initializes jJMenuBar
+ *
+ * @return javax.swing.JMenuBar
+ */
+ private JMenuBar getJJMenuBar() {
+ if (jJMenuBar == null) {
+ jJMenuBar = new JMenuBar();
+ jJMenuBar.add(getJMenu());
+ }
+ return jJMenuBar;
+ }
+
+ /**
+ * This method initializes jMenu
+ *
+ * @return javax.swing.JMenu
+ */
+ private JMenu getJMenu() {
+ if (jMenu == null) {
+ jMenu = new JMenu();
+ jMenu.setText("File");
+ jMenu.add(getJMenuItem());
+ }
+ return jMenu;
+ }
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getJMenuItem() {
+ if (jMenuItem == null) {
+ jMenuItem = new JMenuItem();
+ jMenuItem.setText("Exit");
+ jMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ exitKT();
+ }
+ });
+ }
+ return jMenuItem;
+ }
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel() {
+ if (jPanel == null) {
+ GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
+ gridBagConstraints41.gridx = 0;
+ gridBagConstraints41.gridy = 1;
+ GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
+ gridBagConstraints3.gridy = 0;
+ gridBagConstraints3.gridx = 0;
+ GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
+ gridBagConstraints2.gridy = 2;
+ gridBagConstraints2.gridx = 1;
+ GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
+ gridBagConstraints1.gridy = 1;
+ gridBagConstraints1.gridx = 1;
+ jLabel = new JLabel();
+ jLabel.setText("Plain Text");
+ jPanel = new JPanel();
+ jPanel.setLayout(new GridBagLayout());
+ jPanel.add(getJButton(), gridBagConstraints1);
+ jPanel.add(getJButton1(), gridBagConstraints2);
+ jPanel.add(jLabel, gridBagConstraints3);
+ jPanel.add(getJTextArea(), gridBagConstraints41);
+ }
+ return jPanel;
+ }
+
+ /**
+ * This method initializes jButton
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton() {
+ if (jButton == null) {
+ jButton = new JButton();
+ jButton.setText("Open");
+ }
+ return jButton;
+ }
+
+ /**
+ * This method initializes jButton1
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton1() {
+ if (jButton1 == null) {
+ jButton1 = new JButton();
+ jButton1.setText("Save");
+ }
+ return jButton1;
+ }
+
+ /**
+ * This method initializes jTextArea
+ *
+ * @return javax.swing.JTextArea
+ */
+ private JTextArea getJTextArea() {
+ if (jTextArea == null) {
+ jTextArea = new JTextArea();
+ jTextArea.setText("Enter plain text here...");
+ jTextArea.addFocusListener(new java.awt.event.FocusListener() {
+ public void focusLost(java.awt.event.FocusEvent e) {
+ myKM.setPlain(jTextArea.getText());
+ }
+ public void focusGained(java.awt.event.FocusEvent e) {
+ }
+ });
+
+ }
+ return jTextArea;
+ }
+
+ /**
+ * This method initializes jPanel1
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel1() {
+ if (jPanel1 == null) {
+ GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
+ gridBagConstraints6.fill = GridBagConstraints.BOTH;
+ gridBagConstraints6.gridy = 2;
+ gridBagConstraints6.weightx = 1.0;
+ gridBagConstraints6.weighty = 1.0;
+ gridBagConstraints6.gridwidth = 1;
+ gridBagConstraints6.gridx = 0;
+ GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
+ gridBagConstraints5.gridx = 1;
+ gridBagConstraints5.gridy = 1;
+ GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
+ gridBagConstraints4.gridx = 0;
+ gridBagConstraints4.gridy = 1;
+ jLabel1 = new JLabel();
+ jLabel1.setText("Cipher");
+ jPanel1 = new JPanel();
+ jPanel1.setLayout(new GridBagLayout());
+ jPanel1.add(jLabel1, new GridBagConstraints());
+ jPanel1.add(getJButton2(), gridBagConstraints4);
+ jPanel1.add(getJButton3(), gridBagConstraints5);
+ jPanel1.add(getJTextArea1(), gridBagConstraints6);
+ }
+ return jPanel1;
+ }
+
+ /**
+ * This method initializes jButton2
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton2() {
+ if (jButton2 == null) {
+ jButton2 = new JButton();
+ jButton2.setText("Open");
+ }
+ return jButton2;
+ }
+
+ /**
+ * This method initializes jButton3
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton3() {
+ if (jButton3 == null) {
+ jButton3 = new JButton();
+ jButton3.setText("Save");
+ }
+ return jButton3;
+ }
+
+ /**
+ * This method initializes jTextArea1
+ *
+ * @return javax.swing.JTextArea
+ */
+ private JTextArea getJTextArea1() {
+ if (jTextArea1 == null) {
+ jTextArea1 = new JTextArea();
+ jTextArea1.setText("Enter cipher here...");
+ jTextArea1.addFocusListener(new java.awt.event.FocusListener() {
+ public void focusLost(java.awt.event.FocusEvent e) {
+ myKM.setCipher(jTextArea1.getText());
+ }
+ public void focusGained(java.awt.event.FocusEvent e) {
+ }
+ });
+ }
+ return jTextArea1;
+ }
+
+ /**
+ * This method initializes jPanel2
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel2() {
+ if (jPanel2 == null) {
+
+ GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
+ gridBagConstraints21.gridheight = 1;
+ GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
+ gridBagConstraints19.gridx = 7;
+ gridBagConstraints19.gridy = 1;
+ GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
+ gridBagConstraints13.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints13.weightx = 1.0;
+ GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
+ gridBagConstraints12.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints12.weightx = 1.0;
+ jLabel13 = new JLabel();
+ jLabel13.setText("Vignere-Chiffre");
+ GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
+ gridBagConstraints10.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints10.weightx = 1.0;
+ GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
+ gridBagConstraints9.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints9.weightx = 1.0;
+ GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
+ gridBagConstraints8.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints8.weightx = 1.0;
+ GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
+ gridBagConstraints7.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints7.weightx = 1.0;
+ GridBagConstraints gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints.weightx = 1.0;
+ jLabel17 = new JLabel();
+ jLabel17.setText("undefined");
+ jLabel16 = new JLabel();
+ jLabel16.setText("Inverse:");
+ bg = new ButtonGroup();
+ jLabel12 = new JLabel();
+ jLabel12.setText("Tausch-Chiffre");
+ jLabel11 = new JLabel();
+ jLabel11.setText("P2:");
+ jLabel10 = new JLabel();
+ jLabel10.setText("P1:");
+ jLabel9 = new JLabel();
+ jLabel9.setText("C2:");
+ jLabel8 = new JLabel();
+ jLabel8.setText("C1:");
+ jLabel7 = new JLabel();
+ jLabel7.setText("Method");
+ jLabel6 = new JLabel();
+ jLabel6.setText("Known Plain Text Attack");
+ jLabel5 = new JLabel();
+ jLabel5.setText("Modulus m:");
+ jLabel4 = new JLabel();
+ jLabel4.setText("Key s:");
+ jLabel3 = new JLabel();
+ jLabel3.setText("Key t:");
+ jLabel2 = new JLabel();
+ jLabel2.setText("Krypto parameter");
+ jPanel2 = new JPanel();
+ jPanel2.setLayout(new GridBagLayout());
+
+ jPanel2.add(jLabel2, gridBagConstraints21);
+ jPanel2.add(jLabel16, new GridBagConstraints());
+ jPanel2.add(getJButton8(), new GridBagConstraints());
+ jPanel2.add(jLabel3, new GridBagConstraints());
+ jPanel2.add(jLabel4, new GridBagConstraints());
+ jPanel2.add(getJTextField2(), gridBagConstraints);
+ jPanel2.add(jLabel10, new GridBagConstraints());
+ jPanel2.add(jLabel5, gridBagConstraints19);
+ jPanel2.add(jLabel6, new GridBagConstraints());
+ jPanel2.add(jLabel7, new GridBagConstraints());
+ jPanel2.add(getJButton9(), new GridBagConstraints());
+ jPanel2.add(jLabel8, new GridBagConstraints());
+ jPanel2.add(jLabel9, new GridBagConstraints());
+ jPanel2.add(getJTextField3(), gridBagConstraints7);
+ jPanel2.add(getJTextField4(), gridBagConstraints8);
+ jPanel2.add(getJTextField5(), gridBagConstraints9);
+ jPanel2.add(getJTextField6(), gridBagConstraints10);
+ jPanel2.add(getJButton7(), new GridBagConstraints());
+ jPanel2.add(getJRadioButton(), new GridBagConstraints());
+ jPanel2.add(jLabel13, new GridBagConstraints());
+ jPanel2.add(getJTextField1(), gridBagConstraints12);
+ jPanel2.add(jLabel11, new GridBagConstraints());
+ jPanel2.add(jLabel12, new GridBagConstraints());
+ jPanel2.add(getJRadioButton1(), new GridBagConstraints());
+ jPanel2.add(getJTextField(), gridBagConstraints13);
+ jPanel2.add(jLabel17, new GridBagConstraints());
+ bg.add(jRadioButton);
+ bg.add(jRadioButton1);
+ }
+ return jPanel2;
+ }
+
+ /**
+ * This method initializes jButton4
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton4() {
+ if (jButton4 == null) {
+ jButton4 = new JButton();
+ jButton4.setText("Encrypt");
+ jButton4.setName("jButton4");
+ jButton4.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ myKM.encrypt();
+ }
+ });
+ }
+ return jButton4;
+ }
+
+ /**
+ * This method initializes jButton5
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton5() {
+ if (jButton5 == null) {
+ jButton5 = new JButton();
+ jButton5.setText("Decrypt");
+ jButton5.setName("jButton5");
+ jButton5.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ myKM.decrypt();
+ }
+ });
+ }
+ return jButton5;
+ }
+
+ /**
+ * This method initializes jButton6
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton6() {
+ if (jButton6 == null) {
+ jButton6 = new JButton();
+ jButton6.setText("Attack");
+ jButton6.setName("jButton6");
+ jButton6.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ myKM.attack();
+ }
+ });
+ }
+ return jButton6;
+ }
+
+ /**
+ * This method initializes jTextField
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getJTextField() {
+ if (jTextField == null) {
+ jTextField = new JTextField("key t...",10);
+ jTextField.setToolTipText("Enter key t here");
+ IntVerifier iv = new IntVerifier();
+ jTextField.setInputVerifier(iv);
+ jTextField.addFocusListener(new java.awt.event.FocusListener() {
+ public void focusGained(java.awt.event.FocusEvent e) {
+ jTextField.setText("");
+ }
+ public void focusLost(java.awt.event.FocusEvent e) {
+ try
+ {
+ int temp = Integer.parseInt(jTextField.getText());
+ myKM.setkey_t(temp);
+ }
+
+ catch (NumberFormatException nfe) {}
+
+ }
+ });
+ }
+ return jTextField;
+ }
+
+ /**
+ * This method initializes jTextField1
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getJTextField1() {
+ if (jTextField1 == null) {
+ jTextField1 = new JTextField("key s...",10);
+ jTextField1.setToolTipText("Enter key s here");
+ IntVerifier iv = new IntVerifier();
+ jTextField1.setInputVerifier(iv);
+ jTextField1.addFocusListener(new java.awt.event.FocusListener() {
+ public void focusGained(java.awt.event.FocusEvent e) {
+ jTextField1.setText("");
+ }
+ public void focusLost(java.awt.event.FocusEvent e) {
+ try {
+ myKM.setkey_s(Integer.parseInt(jTextField1.getText()));
+ }
+ catch (NumberFormatException nfe) {}
+ }
+ });
+ }
+ return jTextField1;
+ }
+
+ /**
+ * This method initializes jTextField2
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getJTextField2() {
+ if (jTextField2 == null) {
+ jTextField2 = new JTextField("modulus m:",10);
+ jTextField2.setToolTipText("Enter Modulus m here");
+ IntVerifier iv = new IntVerifier();
+ jTextField2.setInputVerifier(iv);
+ jTextField2.addFocusListener(new java.awt.event.FocusListener() {
+ public void focusGained(java.awt.event.FocusEvent e) {
+ jTextField2.setText("");
+ }
+ public void focusLost(java.awt.event.FocusEvent e) {
+ try
+ {
+ int temp = Integer.parseInt(jTextField2.getText());
+ myKM.setmod(temp);
+ }
+
+ catch (NumberFormatException nfe) {}
+
+ }
+ });
+ }
+ return jTextField2;
+ }
+
+ /**
+ * This method initializes jTextField3
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getJTextField3() {
+ if (jTextField3 == null) {
+ jTextField3 = new JTextField("p1...",10);
+ }
+ return jTextField3;
+ }
+
+ /**
+ * This method initializes jTextField4
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getJTextField4() {
+ if (jTextField4 == null) {
+ jTextField4 = new JTextField("p2...",10);
+ }
+ return jTextField4;
+ }
+
+ /**
+ * This method initializes jTextField5
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getJTextField5() {
+ if (jTextField5 == null) {
+ jTextField5 = new JTextField("c1...",10);
+ }
+ return jTextField5;
+ }
+
+ /**
+ * This method initializes jTextField6
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getJTextField6() {
+ if (jTextField6 == null) {
+ jTextField6 = new JTextField("c2...",10);
+ }
+ return jTextField6;
+ }
+ private void exitKT()
+ {
+ System.exit(0);
+ }
+ /**
+ * This method initializes jButton7
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton7() {
+ if (jButton7 == null) {
+ jButton7 = new JButton();
+ jButton7.setText("Generate Modulus");
+ jButton7.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ myKM.genMod();
+ }
+ });
+ }
+ return jButton7;
+ }
+
+ /**
+ * This method initializes jRadioButton
+ *
+ * @return javax.swing.JRadioButton
+ */
+ private JRadioButton getJRadioButton() {
+ if (jRadioButton == null) {
+ jRadioButton = new JRadioButton();
+ jRadioButton.setSelected(true);
+ jRadioButton.addItemListener(new java.awt.event.ItemListener() {
+ public void itemStateChanged(java.awt.event.ItemEvent e) {
+ if (jRadioButton.isSelected())
+ myKM.setMethod("TAUSCH");
+ }
+ });
+ }
+ return jRadioButton;
+ }
+
+ /**
+ * This method initializes jRadioButton1
+ *
+ * @return javax.swing.JRadioButton
+ */
+ private JRadioButton getJRadioButton1() {
+ if (jRadioButton1 == null) {
+ jRadioButton1 = new JRadioButton();
+ jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
+ public void itemStateChanged(java.awt.event.ItemEvent e) {
+ if (jRadioButton1.isSelected())
+ myKM.setMethod("VIGNERE");
+ }
+ });
+ }
+ return jRadioButton1;
+ }
+
+ /**
+ * This method initializes jPanel4
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel4() {
+ if (jPanel4 == null) {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.setRows(1);
+ gridLayout.setColumns(4);
+ jLabel15 = new JLabel();
+ jLabel15.setText("");
+ jLabel14 = new JLabel();
+ jLabel14.setText("Status: ");
+ jPanel4 = new JPanel();
+ jPanel4.setLayout(gridLayout);
+ jPanel4.add(jLabel14, null);
+ jPanel4.add(jLabel15, null);
+ }
+ return jPanel4;
+ }
+
+ /**
+ * This method initializes jButton8
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton8() {
+ if (jButton8 == null) {
+ jButton8 = new JButton();
+ jButton8.setText("Calc. Inv.");
+ jButton8.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ myKM.calcModInv();
+ }
+ });
+ }
+ return jButton8;
+ }
+
+ /**
+ * This method initializes jPanel5
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel5() {
+ if (jPanel5 == null) {
+ GridLayout gridLayout1 = new GridLayout();
+ gridLayout1.setRows(0);
+ gridLayout1.setColumns(3);
+ GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
+ gridBagConstraints11.gridy = 3;
+ gridBagConstraints11.fill = GridBagConstraints.BOTH;
+ gridBagConstraints11.gridx = 1;
+ jPanel5 = new JPanel();
+ jPanel5.setLayout(gridLayout1);
+ jPanel5.add(getJButton4(), null);
+ jPanel5.add(getJButton5(), null);
+ jPanel5.add(getJButton6(), null);
+ }
+ return jPanel5;
+ }
+
+ /**
+ * This method initializes jButton9
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton9() {
+ if (jButton9 == null) {
+ jButton9 = new JButton();
+ jButton9.setText("Set known pairs");
+ jButton9.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ char p1,c1,p2,c2;
+ p1=jTextField3.getText().charAt(0);
+ c1=jTextField5.getText().charAt(0);
+ p2=jTextField4.getText().charAt(0);
+ c2=jTextField6.getText().charAt(0);
+ myKM.setKnownPlain(p1,c1,p2,c2);
+ }
+ });
+ }
+ return jButton9;
+ }
+
+ public static void main (String[] argv)
+ {
+ KryptTool myKT = new KryptTool();
+
+ //myKT.initialize();
+ myKT.setVisible(true);
+ }
+} // @jve:decl-index=0:visual-constraint="10,10"