Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1. public BigInteger WIENER(BigInteger message){
  2.        
  3.         List<BigInteger> list = new ArrayList<BigInteger>();
  4.         List<BigInteger> list_alpha = new ArrayList<BigInteger>();
  5.         List<BigInteger> list_beta = new ArrayList<BigInteger>();
  6.  
  7.  
  8.         BigInteger  p, q, n, phin, alpha, beta, p_new, q_new, phi, delta;
  9.         int i;
  10.        
  11.         phi=BigInteger.valueOf(0);
  12.         delta=BigInteger.valueOf(0);
  13.         p = this.p;
  14.         q = this.q;
  15.         n = this.n;
  16.         phin = this.phin;
  17.         Random rnd = new Random();
  18.        
  19.         do {
  20.             d = new BigInteger(254, rnd);
  21.         } while (d.compareTo(phin) != -1 || BigInteger.valueOf(1).compareTo(phin.gcd(d)) != 0);//d>=phin || cmmdc(d,phin)!=1
  22.         e = d.modInverse(phin);
  23.        
  24.         //System.out.println((e.multiply(d)).mod(phin));// verific
  25.      
  26.         //euclid en
  27.         Euclid(e,n,list); // construieste o liste cu toate caturile
  28.        
  29.        
  30.         i = 0;
  31.         do{
  32.             System.out.println(phi);
  33.             System.out.println(delta);
  34.  
  35.             i++;
  36.             if(i == 1){
  37.                 alpha = list.get(1);
  38.                 beta = BigInteger.valueOf(1);
  39.             }
  40.             else if(i == 2){
  41.                 alpha = ((list.get(1)).multiply(list.get(2))).add(BigInteger.valueOf(1));//q1*q2+1
  42.                 beta = list.get(2);
  43.             }
  44.             else{
  45.                 alpha = ((list.get(i)).multiply(list_alpha.get(i-1))).add(list_alpha.get(i-2));//qi*q(i-1)+q(i-2)
  46.                 beta = ((list.get(i)).multiply(list_beta.get(i-1))).add(list_beta.get(i-2));//qi*q(i-1)+q(i-2)            
  47.             }
  48.             list_alpha.add(alpha);
  49.             list_beta.add(beta);
  50.         }
  51.         while(Criteriu(alpha, beta, e, n,phi,delta) != 1);//cand criteriu(l,d)=1 => am gasiti + 1;
  52.        
  53.         return p;
  54.     }
  55.      
  56.     public int Criteriu(BigInteger l, BigInteger d, BigInteger e, BigInteger n,BigInteger phi, BigInteger delta){
  57.         //BigInteger phi, delta;
  58.         if((((e.multiply(d)).add(BigInteger.valueOf(-1))).mod(l)).equals(BigInteger.valueOf(0))){ //(ed - 1)%d = 0;
  59.             phi = ((e.multiply(d)).add(BigInteger.valueOf(-1))).divide(l);
  60.             //ecuatia: x^2 + (n-phi+1)x + n = 0
  61.             //delta = b^2 -4ac
  62.             //delta = (n-phi+1)*(n-phi+1) -4*n;
  63.             delta = (((n.subtract(phi)).add(BigInteger.valueOf(1))).multiply((n.subtract(phi)).add(BigInteger.valueOf(1)))).subtract(n.multiply(BigInteger.valueOf(4)));
  64.             if(sqrt(delta).multiply(sqrt(delta)) == delta)
  65.                 return 1;
  66.         }
  67.         return 0;
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement