| 43 | } |
| 44 | |
| 45 | public void actionPerformed(ActionEvent e) { |
| 46 | String key = keyField.getText(); |
| 47 | String input = inputField.getText(); |
| 48 | |
| 49 | try { |
| 50 | if (e.getSource() == encryptButton) { |
| 51 | String encryptedText = encrypt(key, input); |
| 52 | outputArea.setText("Encrypted Text:\n" + encryptedText); |
| 53 | } else if (e.getSource() == decryptButton) { |
| 54 | String decryptedText = decrypt(key, input); |
| 55 | outputArea.setText("Decrypted Text:\n" + decryptedText); |
| 56 | } |
| 57 | } catch (Exception ex) { |
| 58 | outputArea.setText("Error: " + ex.getMessage()); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | private String encrypt(String key, String input) throws Exception { |
| 63 | Cipher cipher = Cipher.getInstance(TRANSFORMATION); |