Hi all,

I'm currently working on a RSA Encryption using Fast Exponential technique. As the numbers I'm working with will be very huge, I am forced to use BigInteger.

As this is the first time I'm using Big Integer, I encountered quite a number of issues. I'll try my best to explain the errors I'm facing:

1. I had done this step: BigInteger d;

So I'm currently trying to get d = 0;

However, I keep getting an error required: BigInteger, found int.

When I changed it to d = new BigInteger(0) , I get this error:

java:19: error: constructor BigInteger in class BigInteger cannot be applied to given types;

d = new BigInteger(0);

^

required: no arguments

found: int

reason: actual and formal argument lists differ in length

Part of Code:

public class BigFastExponential

{

BigInteger e; // public exponenet: all has this

BigInteger d; // private key: only key owner has this

BigInteger n; // public modulus: all has this

/**

* Create a LongRSA object for a public key holder,

* with just e and n.

*/

public BigFastExponential(BigInteger public_e, BigInteger public_n)

{

e = public_e;

n = public_n;

d = new BigInteger(0);

}

2. Similar to above, I tried the following if (d == 0).

I also tried :

BigInteger = result;

result = 1;

This is the error I received:

java:57: error: incomparable types: BigInteger and int

if (d == 0) {

^

BigFastExponential.java:77: error: incompatible types

result = 1;

^

required: BigInteger

found: int

3. I'm also getting some erros about the operators for BigIntegers. All these used to work when I was using LONG instead of BigInteger.

Error:

BigFastExponential.java:79: error: bad operand types for binary operator '>'

while (e > 0)

^

first type: BigInteger

second type: int

BigFastExponential.java:81: error: bad operand types for binary operator '&'

if ((e & 1) == 1) // & = bitwise &&

^

first type: BigInteger

second type: int

BigFastExponential.java:83: error: bad operand types for binary operator '*'

result = (result * b) % n;

^

first type: BigInteger

second type: BigInteger

BigFastExponential.java:85: error: bad operand types for binary operator '>>'

e = e >> 1;

^

first type: BigInteger

second type: int

BigFastExponential.java:86: error: bad operand types for binary operator '*'

b = (b * b) % n;

^

first type: BigInteger

second type: BigInteger

Code segment:

public BigInteger decrypt(BigInteger c) {

if (d == 0) {

throw new IllegalStateException("No private key value set.");

}

BigInteger M;

M = modpow(c, d, n);

return M;

}

public static final BigInteger modpow(BigInteger b, BigInteger e, BigInteger n)

{

BigInteger result;

result = 1;

while (e > 0)

{

if ((e & 1) == 1) // & = bitwise &&

{

result = (result * b) % n;

}

e = e >> 1;

b = (b * b) % n;

}

return result;

}

4. Last but not least, I did my research and I was told that to get input as BigInteger, I have to use scanner.nextBigInteger();

I did so but I received a very weird error:

BigFastExponential.java:104: error: incompatible types

n = user_input.nextBigInteger();

^

required: BigInteger

found: java.math.BigInteger

Are they different ?

Code Segment:

public static void main(String[] args)

{

BigInteger p;

BigInteger q;

BigInteger e;

BigInteger n;

BigInteger d;

BigInteger M;

// Lab 2 - (2)(a) Bob uses PublicAlice key to encrypt a plaintext message M

Scanner user_input = new Scanner (System.in);

System.out.print("Enter value of n: "); // n = value of pq. Bob does NOT know p and q, only n

n = user_input.nextBigInteger();

System.out.print("Enter value of e: "); // (pq/n,e) = Public Alice Key

e = user_input.nextBigInteger();

System.out.print("Enter value of d: "); // for decryption using Private Alice Key

d = user_input.nextBigInteger();

Thanks in advance for all your help ! Sorry for the long list of questions on my very first post !

Warmest Regards,

Zeke