Add move number to encrypted text field 2 button
Limit length of keys to 50 bits Add basic input validation
This commit is contained in:
parent
332ccf142e
commit
225c87bc31
@ -60,14 +60,6 @@
|
|||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
</component>
|
</component>
|
||||||
<component id="f31a0" class="javax.swing.JTextField" binding="encryptedNumber2">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="150" height="-1"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="4096" class="javax.swing.JButton" binding="cryptButton" default-binding="true">
|
<component id="4096" class="javax.swing.JButton" binding="cryptButton" default-binding="true">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
@ -76,14 +68,6 @@
|
|||||||
<text value="Crypt"/>
|
<text value="Crypt"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="717e0" class="javax.swing.JButton" binding="decryptButton" default-binding="true">
|
|
||||||
<constraints>
|
|
||||||
<grid row="8" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Decrypt"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="7dd2a" class="javax.swing.JLabel">
|
<component id="7dd2a" class="javax.swing.JLabel">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
@ -92,14 +76,6 @@
|
|||||||
<text value="Plain number:"/>
|
<text value="Plain number:"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="b4aca" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="4" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Encrypted number:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="5d2a6" class="javax.swing.JTextField" binding="encryptedNumber">
|
<component id="5d2a6" class="javax.swing.JTextField" binding="encryptedNumber">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
@ -116,22 +92,6 @@
|
|||||||
<text value="Encrypted number:"/>
|
<text value="Encrypted number:"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="df950" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Decrypted number:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="2a7e2" class="javax.swing.JTextField" binding="decryptedNumber">
|
|
||||||
<constraints>
|
|
||||||
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="150" height="-1"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
</component>
|
|
||||||
<component id="bc95a" class="javax.swing.JSlider" binding="keylength">
|
<component id="bc95a" class="javax.swing.JSlider" binding="keylength">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
@ -143,14 +103,6 @@
|
|||||||
<JSlider.isFilled class="java.lang.Boolean" value="false"/>
|
<JSlider.isFilled class="java.lang.Boolean" value="false"/>
|
||||||
</clientProperties>
|
</clientProperties>
|
||||||
</component>
|
</component>
|
||||||
<component id="de444" class="javax.swing.JLabel">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Key length:"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="aeaa8" class="javax.swing.JButton" binding="generateKeysButton" default-binding="true">
|
<component id="aeaa8" class="javax.swing.JButton" binding="generateKeysButton" default-binding="true">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
@ -181,8 +133,66 @@
|
|||||||
<preferred-size width="150" height="50"/>
|
<preferred-size width="150" height="50"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<lineWrap value="true"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2a7e2" class="javax.swing.JTextField" binding="decryptedNumber">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
</component>
|
</component>
|
||||||
|
<component id="df950" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Decrypted number:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b4aca" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Encrypted number:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="f31a0" class="javax.swing.JTextField" binding="encryptedNumber2">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="e0956" class="javax.swing.JButton" binding="moveNumberButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="------------------->"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="717e0" class="javax.swing.JButton" binding="decryptButton" default-binding="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Decrypt"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="de444" class="javax.swing.JLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Key length:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</children>
|
</children>
|
||||||
|
@ -19,6 +19,7 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
|
|||||||
private JSlider keylength;
|
private JSlider keylength;
|
||||||
private JLabel keylengthLabel;
|
private JLabel keylengthLabel;
|
||||||
private JTextArea moduleTextArea;
|
private JTextArea moduleTextArea;
|
||||||
|
private JButton moveNumberButton;
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
private RSA rsa;
|
private RSA rsa;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
|
|||||||
cryptButton.addActionListener(this);
|
cryptButton.addActionListener(this);
|
||||||
decryptButton.addActionListener(this);
|
decryptButton.addActionListener(this);
|
||||||
keylength.setMinimum(8);
|
keylength.setMinimum(8);
|
||||||
keylength.setMaximum(64);
|
keylength.setMaximum(50);
|
||||||
keylength.setMajorTickSpacing(10);
|
keylength.setMajorTickSpacing(10);
|
||||||
keylength.setMinorTickSpacing(5);
|
keylength.setMinorTickSpacing(5);
|
||||||
keylength.setValue(32);
|
keylength.setValue(32);
|
||||||
@ -38,6 +39,7 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
|
|||||||
keylength.setPaintLabels(true);
|
keylength.setPaintLabels(true);
|
||||||
keylength.addChangeListener(this);
|
keylength.addChangeListener(this);
|
||||||
keylengthLabel.setText(String.valueOf(keylength.getValue()));
|
keylengthLabel.setText(String.valueOf(keylength.getValue()));
|
||||||
|
moveNumberButton.addActionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stateChanged(ChangeEvent e){
|
public void stateChanged(ChangeEvent e){
|
||||||
@ -51,18 +53,26 @@ public class MainWindow extends JDialog implements ChangeListener, ActionListene
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JButton source = (JButton) e.getSource();
|
JButton source = (JButton) e.getSource();
|
||||||
if (source == this.cryptButton) {
|
if (source == this.cryptButton) {
|
||||||
BigInteger message = new BigInteger(this.plainNumber.getText());
|
try {
|
||||||
BigInteger key = new BigInteger(this.publicKeyTextArea.getText());
|
BigInteger message = new BigInteger(this.plainNumber.getText());
|
||||||
BigInteger module = new BigInteger(this.moduleTextArea.getText());
|
BigInteger key = new BigInteger(this.publicKeyTextArea.getText());
|
||||||
String encrypted = RSA.cipher(message, key, module).toString();
|
BigInteger module = new BigInteger(this.moduleTextArea.getText());
|
||||||
this.encryptedNumber.setText(encrypted);
|
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) {
|
} else if (source == this.decryptButton) {
|
||||||
BigInteger encryNumber = new BigInteger(this.encryptedNumber2.getText());
|
try {
|
||||||
BigInteger key = new BigInteger(this.privateKeyTextArea.getText());
|
BigInteger encryNumber = new BigInteger(this.encryptedNumber2.getText());
|
||||||
BigInteger module = new BigInteger(this.moduleTextArea.getText());
|
BigInteger key = new BigInteger(this.privateKeyTextArea.getText());
|
||||||
String decrypted = RSA.cipher(encryNumber, key, module).toString();
|
BigInteger module = new BigInteger(this.moduleTextArea.getText());
|
||||||
this.decryptedNumber.setText(decrypted);
|
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) {
|
} else if (source == this.generateKeysButton) {
|
||||||
this.rsa = new RSA(this.keylength.getValue());
|
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.publicKeyTextArea.setText(this.rsa.getPublicKey()+"");
|
||||||
this.privateKeyTextArea.setText(this.rsa.getPrivateKey()+"");
|
this.privateKeyTextArea.setText(this.rsa.getPrivateKey()+"");
|
||||||
this.moduleTextArea.setText(this.rsa.getRSAModule()+"");
|
this.moduleTextArea.setText(this.rsa.getRSAModule()+"");
|
||||||
|
} else if (source == this.moveNumberButton) {
|
||||||
|
this.encryptedNumber2.setText(this.encryptedNumber.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
MainWindow dialog = new MainWindow();
|
MainWindow dialog = new MainWindow();
|
||||||
dialog.pack();
|
dialog.pack();
|
||||||
|
Loading…
Reference in New Issue
Block a user