Monday 28 March 2016

DUAL RSA SMALL-e


Here , is the practical implementation of DUAL RSA to generate public key and private key.
DUAL RSA provides more security than original one and brutttttte force is impossible.





/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rsa;

import java.math.*;
import java.security.SecureRandom;
import java.util.Scanner;
public class DualRSA {
    
    public static void main(String[] args) {
        int n=102,ne=40;//Change the value of n and ne correspoing to your requirement
        BigInteger bi1 = new BigInteger("2");
        BigInteger bi2 = new BigInteger("3");
        BigInteger bi3 = new BigInteger("3");
        boolean b1=false,b2=false;
        // perform isProbablePrime on bi1, bi2
        
        while(!(b1))
        {
            bi1 =  new BigInteger(n,new SecureRandom());
            bi2 =  new BigInteger(n/2-ne,new SecureRandom());
            bi3 = bi1.multiply(bi2);
            bi3 = bi3.add(BigInteger.ONE);
            b1 = bi3.isProbablePrime(1);
        }
        BigInteger x1;
        BigInteger x2;
        BigInteger p1;
        x1 = bi1;
        x2 = bi2;
        p1 = bi3;
        
        b1 = false;
        BigInteger y2 = new BigInteger("2");
        int i =0;
     while(!b1)
     {
         y2 = new BigInteger(n/2-ne,new SecureRandom());
         bi1 = y2;
         bi2 = x1;
         bi3 = bi1.multiply(bi2);
         bi3 = bi3.add(BigInteger.ONE);
         b1 = bi3.isProbablePrime(1);
         i++;
     }
     BigInteger p2,q1 ;
     p2 = bi3;
     
    b1 = false;
    
    BigInteger y1 = new BigInteger("2");
     while(!b1)
     {
         y1 = new BigInteger(n/2-ne,new SecureRandom());
         bi1 = y1;
         bi2 = y2;
         bi3 = bi1.multiply(bi2);
         bi3 = bi3.add(BigInteger.ONE);
         b1 = bi3.isProbablePrime(1);
     }
     
     q1 = bi3;
    
    BigInteger temp = new BigInteger("1");
    temp = temp.multiply(x1);
    temp = temp.multiply(y1);
    temp = temp.multiply(x2);
    temp = temp.multiply(y2);
    
    BigInteger e = new BigInteger(ne,new SecureRandom());
     b1 = false;
    while(!b1)
    {
        e = new BigInteger(ne,new SecureRandom());
        if(temp.gcd(e).equals(BigInteger.ONE))
            b1 = true;
    }
        //System.out.println("e is generated");
        BigInteger d = new BigInteger(n,new SecureRandom());
        BigInteger t1 = new BigInteger("1");
        BigInteger t2 = new BigInteger("1");
        BigInteger k1 = new BigInteger("1");
        BigInteger q2 = new BigInteger("1");
        b1 = false;
        //System.out.println("Going to find d and k1 using q2");
        //System.out.println("d = " + d);
        
    while(!b1)
    {
        d = d.add(BigInteger.ONE);
      //  System.out.println("d = " + d);
        temp = d.multiply(e);
     //   System.out.println("e*d = " + temp);
        temp = temp.subtract(BigInteger.ONE);
        
        //System.out.println("e*d -1 = " + temp);
        t1 = p1.subtract(BigInteger.ONE);
        //System.out.println("p1-1 " + t1);
        t2 = q1.subtract(BigInteger.ONE);
        //System.out.println("q1-1 " + t2);
        k1 = temp.divide(t1.multiply(t2));
        //System.out.println("p1-1*q1-1  " + k1);
        temp = k1.multiply(x2);
        //System.out.println("x2 " + x2);
        //System.out.println("temp " + temp);
        q2 = temp.add(BigInteger.ONE);
      //  System.out.println("" + q2);
       // Scanner s = new Scanner(System.in);
     
        if(q2.isProbablePrime(1))
            b1 = true;
    }
        System.out.println("Got d and k1 and q2");
    BigInteger N1 ,N2 ,k2;
    N1 = p1.multiply(q1);
    N2 = p2.multiply(q2);
    k2 = y1;
        System.out.println("e = " + e);
        System.out.println("N1 = " + N1);
        System.out.println("N2 = " + N2 );
        System.out.println("\n");
        System.out.println("d = " + d);
        System.out.println("p1 = " + p1);
        System.out.println("q1 = " + q1);
        System.out.println("p2 = " + p2);
        System.out.println("q2 = " + q2);
    
    }


}


For more Info:

No comments:

Post a Comment

How to install google-chrome in redhat without redhat subscription

Install google-chrome in redhat  Download the .rpm file of chrome https://www.google.com/chrome/thank-you.html?installdataindex=empty&st...