Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public BigInteger WIENER(BigInteger message){
- List<BigInteger> list = new ArrayList<BigInteger>();
- List<BigInteger> list_alpha = new ArrayList<BigInteger>();
- List<BigInteger> list_beta = new ArrayList<BigInteger>();
- BigInteger p, q, n, phin, alpha, beta, p_new, q_new, phi, delta;
- int i;
- phi=BigInteger.valueOf(0);
- delta=BigInteger.valueOf(0);
- p = this.p;
- q = this.q;
- n = this.n;
- phin = this.phin;
- Random rnd = new Random();
- do {
- d = new BigInteger(254, rnd);
- } while (d.compareTo(phin) != -1 || BigInteger.valueOf(1).compareTo(phin.gcd(d)) != 0);//d>=phin || cmmdc(d,phin)!=1
- e = d.modInverse(phin);
- //System.out.println((e.multiply(d)).mod(phin));// verific
- //euclid en
- Euclid(e,n,list); // construieste o liste cu toate caturile
- i = 0;
- do{
- System.out.println(phi);
- System.out.println(delta);
- i++;
- if(i == 1){
- alpha = list.get(1);
- beta = BigInteger.valueOf(1);
- }
- else if(i == 2){
- alpha = ((list.get(1)).multiply(list.get(2))).add(BigInteger.valueOf(1));//q1*q2+1
- beta = list.get(2);
- }
- else{
- alpha = ((list.get(i)).multiply(list_alpha.get(i-1))).add(list_alpha.get(i-2));//qi*q(i-1)+q(i-2)
- beta = ((list.get(i)).multiply(list_beta.get(i-1))).add(list_beta.get(i-2));//qi*q(i-1)+q(i-2)
- }
- list_alpha.add(alpha);
- list_beta.add(beta);
- }
- while(Criteriu(alpha, beta, e, n,phi,delta) != 1);//cand criteriu(l,d)=1 => am gasiti + 1;
- return p;
- }
- public int Criteriu(BigInteger l, BigInteger d, BigInteger e, BigInteger n,BigInteger phi, BigInteger delta){
- //BigInteger phi, delta;
- if((((e.multiply(d)).add(BigInteger.valueOf(-1))).mod(l)).equals(BigInteger.valueOf(0))){ //(ed - 1)%d = 0;
- phi = ((e.multiply(d)).add(BigInteger.valueOf(-1))).divide(l);
- //ecuatia: x^2 + (n-phi+1)x + n = 0
- //delta = b^2 -4ac
- //delta = (n-phi+1)*(n-phi+1) -4*n;
- delta = (((n.subtract(phi)).add(BigInteger.valueOf(1))).multiply((n.subtract(phi)).add(BigInteger.valueOf(1)))).subtract(n.multiply(BigInteger.valueOf(4)));
- if(sqrt(delta).multiply(sqrt(delta)) == delta)
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement