Permalink
Browse files

Fixed encryption bug and added an input dialog where a bit length is …

…provided
  • Loading branch information...
1 parent 4ba601b commit 93553fad1bb5853b47c0c8a2e0223a6dd204421c @johanbrook committed Nov 24, 2011
Showing with 19 additions and 6 deletions.
  1. +4 −4 src/rsa/RSA.java
  2. +15 −2 src/rsa/RSAFrame.java
View
@@ -14,10 +14,10 @@
private BigInteger publicKey;
private BigInteger privateKey;
- public RSA(){
- BigInteger p = BigInteger.probablePrime(5, new Random());
- BigInteger q = BigInteger.probablePrime(5, new Random());
- BigInteger phi = (p.add(one)).multiply(q.subtract(one));
+ public RSA(int bitLength){
+ BigInteger p = BigInteger.probablePrime(bitLength / 2, new Random());
+ BigInteger q = BigInteger.probablePrime(bitLength / 2, new Random());
+ BigInteger phi = (p.subtract(one)).multiply(q.subtract(one));
this.modulus = p.multiply(q);
this.publicKey = new BigInteger("65537");
View
@@ -2,8 +2,8 @@
import java.awt.*;
import java.awt.event.*;
-
import javax.swing.*;
+import javax.swing.JOptionPane;
public class RSAFrame extends JFrame {
@@ -26,7 +26,20 @@ public RSAFrame(){
setLayout(new GridLayout(3, 1));
- tool = new RSA();
+ String bitLength = JOptionPane.showInputDialog(this, "Please provide a bit length");
+
+ if(bitLength == null){
+ System.exit(0);
+ }
+ else{
+ try{
+ tool = new RSA(Integer.parseInt(bitLength));
+ }
+ catch(NumberFormatException e){
+ JOptionPane.showMessageDialog(this, "Please provide a legal integer!");
+ }
+ }
+
JLabel pubKey = new JLabel(tool.getPublicKey().toString());

0 comments on commit 93553fa

Please sign in to comment.