as i m working on implementation of rsa algorithm,and during maiking console of it i found an error int cannot be dereferenced and i m unable to solve it because of working on java first tym...help me here is my code

``````import java.lang.*;
import java.math.*;
import java.util.*;
class rsa
{
int p,q,n,g,d,k,m;
int e=1;
int ct,pt;
int number()
{
Scanner in = new Scanner(System.in);
System.out.println("enter the prime value ");
p = in.nextInt();
int flag = 1;
for(int i=2;i<p;i++)
{
if(p%i==0)
{
System.out.println(p+" is not a Prime Number");
flag = 0;
break;
}
}

if(flag==1)
{
System.out.println(p+" is a Prime Number");
return p;
}

else
return 0;
}
/***********************************************************************/
void calculate(int x,int y)
{
p=x;
q=y;
int count =0;
try
{
int i;
n = p*q;
System.out.println("value of n :"+n);
g=(p-1)*(q-1);
System.out.println("value of g :"+g);
}
catch(Exception e)
{
System.out.println("error"+e.getMessage());
}
}
/************************************************************************/

/***********************************************************************/

int formula()
{

//(d*e) mod g = 1;
d =  e.modInverse(g)  ;
System.out.println("value of d "+d);

System.out.println("Encryption process started:");
Scanner scan = new Scanner(System.in);
System.out.println("enter the  assumed value of plain text:");
pt= scan.nextInt();
ct = pt^e % n;
System.out.println(""+ct);
System.out.println("cipher text ct is send to receiver:");
System.out.println("Decryption process started:");
pt = ct^d%n;
System.out.println(""+pt);
System.out.println("this is original palintext ,process completed thanku");

return 0;
}

}
class rsa061
{
public static void main(String args[])
{    int p=0,q=0;
int m;
rsa r = new rsa();
do
{
p= r.number();

}
while(p==0);

do
{
q= r.number();

}
while(q==0);

r.calculate(p,q);

//n and g

for(int i=r.g; i>2; i--)
{
BigInteger b1 = new BigInteger(""+i); // there's a better way to do this. I forget.
BigInteger b2 = new BigInteger(""+r.g);
BigInteger gcd = b1.gcd(b2);
int c = gcd.intValue();
if(c==1)
{
r.e = i;
System.out.println("E = " + r.e);
break;
}

}

r.formula();
}
}
``````

Line 9, you cannot declare an int as a method/function. Simply implement another method in your rsa class and name it something like getPrimeNumberFromUser() and return a prime number if the number entered by the user is valid. In other words, reimplement lines 9~33 in a method.

Suggestions:
1) Your prime checker should go up to square root of the number itself (use `Math.sqrt`). It will speed up your method by a LOT.
2) You must not allow p and q to be the same number.
3) I don't really see the purpose of having p and q as rsa member variables...

commented: nice suggestion +0