// RSAˆÃ†Œ®‚Ìì¬ import java.math.BigInteger; import java.util.Random; public class RSAkey2 { public static void main (String[] args) { int bit2, bit=50; BigInteger p, q, n, f, e, d, w; BigInteger One = new BigInteger("1"); // set p,q,n p = new BigInteger(bit, 20, new Random()); q = new BigInteger(bit, 20, new Random()); n = p.multiply(q); // æŽZ System.out.println("p="+p.toString()+" q="+q.toString()); System.out.println("n="+n.toString()); // compute f w = p.subtract(One); f = q.subtract(One); f = w.multiply(f); System.out.println("f="+f.toString()); // set e, compute d bit2 = 2*bit - 1; e = new BigInteger(bit2, 20, new Random()); d = e.modInverse(f); System.out.println("e="+e.toString()); System.out.println("d="+d.toString()); } }