
/*
 * Class.java
 *
 * Created on August 31, 2003, 6:21 PM
 */

/**
 *
 * @author  ashish
 */
public class extpr {
    public int p;
    public int g;
    public int publickey;
    public int privatekey;
    
    /** Creates a new instance of Class */
    public extpr(int p,int g,int publickey)  {
        try {
         this.p = p;
         this.g = g;
        this.publickey = publickey;
        
       privatekey = extractprivatekeybruteforce();
        System.out.println("Private key for this configuration is "+ privatekey);
    }catch(Exception e){}
    }
    
   public int  extractprivatekeybruteforce() throws Exception{
        int temp=2;
        int current;
        boolean notfound = true;
            /*This is bruteforce approach*/
         temp = 2;
         current = g * g;
        while (notfound) {
         current = current % this.p;
             if (current == this.publickey) notfound = false;
             if (notfound) {
                 temp++;
                 current *= g;
                                
             }
        }
         return temp;
    }
    
    public static void main(String a[])throws Exception {
        new extpr (24691,106,12375);
         // new extpr ((int)5,(int)2,(int)3);
    }
}
