Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- class HelloWorld {
- public static void main(String[] args) {
- BigInteger one = new BigInteger("1");
- BigInteger two = new BigInteger ("2");
- BigInteger four = new BigInteger("4");
- BigInteger n = new BigInteger("837210799");
- BigInteger e = new BigInteger("7");
- BigInteger e_2 = new BigInteger("17");
- BigInteger d = new BigInteger("478341751");
- BigInteger k = d.multiply(e).subtract(one).divide(n).add(BigInteger.ONE);
- System.out.println("k is "+k);
- BigInteger p_plus_q = k.multiply(n.add(one)).add(one).subtract(e.multiply(d)).divide(k);
- System.out.println("P+q is "+p_plus_q);
- BigInteger delta = p_plus_q.multiply(p_plus_q).subtract(four.multiply(n));
- System.out.println("delta is "+delta);
- BigInteger p =p_plus_q.add(sqrt(delta)).divide(two);
- BigInteger q = p_plus_q.subtract(sqrt(delta)).divide(two);
- System.out.println("P is "+p);
- System.out.println("Q is "+q);
- BigInteger d_2 =e_2.modInverse(p.subtract(one).multiply(q.subtract(one)));
- System.out.println("The second private key is "+d_2);
- }
- public static BigInteger sqrt(BigInteger n) {
- BigInteger a = BigInteger.ONE;
- BigInteger b = n.shiftRight(5).add(BigInteger.valueOf(8));
- while (b.compareTo(a) >= 0) {
- BigInteger mid = a.add(b).shiftRight(1);
- if (mid.multiply(mid).compareTo(n) > 0) {
- b = mid.subtract(BigInteger.ONE);
- } else {
- a = mid.add(BigInteger.ONE);
- }
- }
- return a.subtract(BigInteger.ONE);
- }
- }
Add Comment
Please, Sign In to add comment