Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication6;
  7. import java.math.BigInteger;
  8.  
  9. /**
  10. *
  11. * @author student
  12. */
  13. public class JavaApplication6 {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. BigInteger n1 = new BigInteger("837210799");
  20. BigInteger e1 = new BigInteger("7");
  21. BigInteger d1 = new BigInteger("478341751");
  22. BigInteger n2 = new BigInteger("837210799");
  23. BigInteger e2 = new BigInteger("17");
  24. BigInteger d2;
  25. BigInteger k;
  26. BigInteger zero = new BigInteger("0");
  27. BigInteger one = new BigInteger("1");
  28. BigInteger two = new BigInteger("2");
  29. BigInteger four = new BigInteger("4");
  30. BigInteger pplusq;
  31.  
  32. BigInteger deltaroot;
  33.  
  34. BigInteger p;
  35. BigInteger q;
  36.  
  37. k = d1.multiply(e1).subtract(zero).divide(n1).add(one);
  38. pplusq = one.subtract(d1.multiply(e1)).divide(k).add(n1).add(one);
  39.  
  40.  
  41. deltaroot = sqrt(pplusq.multiply(pplusq).subtract(n1.multiply(four)));
  42. p = pplusq.add(deltaroot).divide(two);
  43. q = pplusq.subtract(deltaroot).divide(two);
  44.  
  45.  
  46. System.out.println(k + "--" + pplusq + "--" + p + " " + q);
  47. }
  48.  
  49. public static BigInteger sqrt(BigInteger x) {
  50. BigInteger div = BigInteger.ZERO.setBit(x.bitLength()/2);
  51. BigInteger div2 = div;
  52. // Loop until we hit the same value twice in a row, or wind
  53. // up alternating.
  54. for(;;) {
  55. BigInteger y = div.add(x.divide(div)).shiftRight(1);
  56. if (y.equals(div) || y.equals(div2))
  57. return y;
  58. div2 = div;
  59. div = y;
  60. }
  61. }
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement