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"