diff --git a/src/MainWindow.form b/src/MainWindow.form
index 1b6c41e..3d59136 100644
--- a/src/MainWindow.form
+++ b/src/MainWindow.form
@@ -60,14 +60,6 @@
-
-
-
-
-
-
-
-
@@ -76,14 +68,6 @@
-
-
-
-
-
-
-
-
@@ -92,14 +76,6 @@
-
-
-
-
-
-
-
-
@@ -116,22 +92,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -143,14 +103,6 @@
-
-
-
-
-
-
-
-
@@ -181,8 +133,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/MainWindow.java b/src/MainWindow.java
index 225c02b..c55adee 100644
--- a/src/MainWindow.java
+++ b/src/MainWindow.java
@@ -19,6 +19,7 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
private JSlider keylength;
private JLabel keylengthLabel;
private JTextArea moduleTextArea;
+ private JButton moveNumberButton;
private JButton buttonOK;
private RSA rsa;
@@ -30,7 +31,7 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
cryptButton.addActionListener(this);
decryptButton.addActionListener(this);
keylength.setMinimum(8);
- keylength.setMaximum(64);
+ keylength.setMaximum(50);
keylength.setMajorTickSpacing(10);
keylength.setMinorTickSpacing(5);
keylength.setValue(32);
@@ -38,6 +39,7 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
keylength.setPaintLabels(true);
keylength.addChangeListener(this);
keylengthLabel.setText(String.valueOf(keylength.getValue()));
+ moveNumberButton.addActionListener(this);
}
public void stateChanged(ChangeEvent e){
@@ -51,18 +53,26 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
public void actionPerformed(ActionEvent e) {
JButton source = (JButton) e.getSource();
if (source == this.cryptButton) {
- BigInteger message = new BigInteger(this.plainNumber.getText());
- BigInteger key = new BigInteger(this.publicKeyTextArea.getText());
- BigInteger module = new BigInteger(this.moduleTextArea.getText());
- String encrypted = RSA.cipher(message, key, module).toString();
- this.encryptedNumber.setText(encrypted);
+ try {
+ BigInteger message = new BigInteger(this.plainNumber.getText());
+ BigInteger key = new BigInteger(this.publicKeyTextArea.getText());
+ BigInteger module = new BigInteger(this.moduleTextArea.getText());
+ String encrypted = RSA.cipher(message, key, module).toString();
+ this.encryptedNumber.setText(encrypted);
+ } catch (NumberFormatException ex) {
+ JOptionPane.showMessageDialog(this, "Invalid value(s), check your input and try again!", "RSA Test", JOptionPane.ERROR_MESSAGE);
+ }
} else if (source == this.decryptButton) {
- BigInteger encryNumber = new BigInteger(this.encryptedNumber2.getText());
- BigInteger key = new BigInteger(this.privateKeyTextArea.getText());
- BigInteger module = new BigInteger(this.moduleTextArea.getText());
- String decrypted = RSA.cipher(encryNumber, key, module).toString();
- this.decryptedNumber.setText(decrypted);
+ try {
+ BigInteger encryNumber = new BigInteger(this.encryptedNumber2.getText());
+ BigInteger key = new BigInteger(this.privateKeyTextArea.getText());
+ BigInteger module = new BigInteger(this.moduleTextArea.getText());
+ String decrypted = RSA.cipher(encryNumber, key, module).toString();
+ this.decryptedNumber.setText(decrypted);
+ } catch (NumberFormatException ex) {
+ JOptionPane.showMessageDialog(this, "Invalid value(s), check your input and try again!", "RSA Test", JOptionPane.ERROR_MESSAGE);
+ }
} else if (source == this.generateKeysButton) {
this.rsa = new RSA(this.keylength.getValue());
@@ -70,10 +80,11 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
this.publicKeyTextArea.setText(this.rsa.getPublicKey()+"");
this.privateKeyTextArea.setText(this.rsa.getPrivateKey()+"");
this.moduleTextArea.setText(this.rsa.getRSAModule()+"");
+ } else if (source == this.moveNumberButton) {
+ this.encryptedNumber2.setText(this.encryptedNumber.getText());
}
}
-
public static void main(String[] args) {
MainWindow dialog = new MainWindow();
dialog.pack();