Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 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 lab6;
  7. import java.math.BigInteger;
  8.  
  9.  
  10. public class Lab6 {
  11.  
  12.    
  13.    
  14.     private static BigInteger NaiveSquareRootSearch(BigInteger a, BigInteger left,BigInteger right){
  15.         // fix root as the arithmetic mean of left and right
  16.         BigInteger root = left.add(right).shiftRight(1);
  17.         // if the root is not between [root, root+1],
  18.         //is not an integer and root is our best integer ap proximation
  19.         if(!((root.pow(2).compareTo(a) == -1)&&(root.add(BigInteger.ONE).pow(2).compareTo(a) == 1))){
  20.             if (root.pow(2).compareTo(a) == -1) root = NaiveSquareRootSearch(a, root,right);
  21.                if (root.pow(2).compareTo(a) == 1) root = NaiveSquareRootSearch(a, left,root);
  22.         }
  23.         return root;
  24.     }
  25.     /**
  26. n=
  27. 5076313634899413540120536350051034312987619378778911504647420938544
  28. 7465177110314901155284204273194792744073890582538974985571109131603
  29. 02801741874277608327,
  30. e=3
  31. d=
  32. 3384209089932942360080357566700689541991746252519274336431613959029
  33. 8310118072592266557861250508877279212747197519861041620378008076415
  34. 22348207376583379547
  35.  
  36. * below find the factorization of the modulus
  37.      */
  38.     public static void main(String[] args) {
  39.        
  40.         BigInteger n = new BigInteger("837210799");
  41.        
  42.         BigInteger d = new BigInteger("478341751");
  43.         BigInteger e = new BigInteger("7");
  44.         BigInteger e2 = new BigInteger("17");
  45.         BigInteger one = new BigInteger("1");
  46.         BigInteger two = new BigInteger("2");
  47.         BigInteger four = new BigInteger("4");
  48.        
  49.         BigInteger k =  (d.multiply(e).subtract(one)).divide(n);
  50.        
  51.        
  52.          k = k.add(one);
  53.         System.out.println("K ii " +k);
  54.        
  55.        
  56.         BigInteger s = (k.multiply((n.add(one))).add(one).subtract(((d.multiply(e)).subtract(one))).divide(k));
  57.        
  58.         System.out.println("S = " +s);
  59.        
  60.    
  61.        
  62.        
  63.        
  64.         BigInteger delta = s.multiply(s).subtract(four.multiply(n));
  65.        
  66.         System.out.println("Delta = " +delta);
  67.  
  68.         BigInteger root1, root2;
  69.         BigInteger sqrt = SRoot(delta);
  70.        
  71.         System.out.println("RadicalDelta = " +sqrt);
  72.        
  73.         root1 = s.add(sqrt).divide(two);  
  74.         root2 = s.subtract(sqrt).divide(two);
  75.            
  76.         System.out.println("ROOT1 = " +root1 + "\n" + "ROOT2 = " +root2);
  77.      
  78.        
  79.        BigInteger d1=e2.modInverse((root1.subtract(one)).multiply(root2.subtract(one)));
  80.        System.out.println("d1: " + d1);
  81. }
  82.    
  83.     public static BigInteger SRoot(BigInteger a){
  84.          return NaiveSquareRootSearch(a, BigInteger.ZERO, a);
  85.     }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement