Incompatible Types Error in Code PLEASE HELP!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Incompatible Types Error in Code PLEASE HELP!!

  1. #1
    Join Date
    Jul 2004
    Posts
    7

    Incompatible Types Error in Code PLEASE HELP!!

    I am getting a incompatible types error from the following segment of code, I am calling my ExtendedEuclid class from the main program, my Extended Euclid class compiles just fine, but the one part in the main will not, it is the part towards the bottom where I am calling the extended euclid class and trying to pass the arguments... Here is some code snippets...

    MY EXTENDED EUCLID CLASS...
    import java.math.BigInteger;
    public class ExtendedEuclid
    {
    public static BigInteger[] ExtendedEuclid(BigInteger a, BigInteger b, BigInteger c, BigInteger d, BigInteger e, BigInteger f)
    {
    BigInteger[] br = new BigInteger[]{a,e,f};
    BigInteger[] ar = new BigInteger[]{b, a.mod(b), e.subtract(a.multiply(c).divide(b)),
    f.subtract(a.multiply(d).divide(b)), c, d};
    if(b.compareTo(BigInteger.ZERO) == 0)
    {
    return br;
    }
    else
    {
    return ar;
    }
    }
    }

    THE CODE FROM THE MAIN PROGRAM GIVING ME ERRORS...

    import java.math.BigInteger;
    import javax.swing.*;
    import java.io.Serializable;
    public class RSA
    {
    public static void main(String[] args)
    {
    MillerRabin MR = new MillerRabin();
    BigInteger p = new BigInteger("0");
    BigInteger q = new BigInteger("0");
    BigInteger a = new BigInteger("1");
    BigInteger b = new BigInteger("1");
    BigInteger D = new BigInteger("1");
    BigInteger gcd = new BigInteger("0");
    BigInteger E = new BigInteger("1");
    BigInteger c0 = new BigInteger("0");
    BigInteger d1 = new BigInteger("1");
    BigInteger f0 = new BigInteger("0");
    Euclid findE = new Euclid();
    ExtendedEuclid findD = new ExtendedEuclid();

    do
    {
    p = MR.createPrime(512,100);

    System.out.println("p = " + p + "\n");

    for(int i = 1; i <=100; i++)
    {
    if(MR.isProbablePrime(p))
    {
    if(i == 100)
    {
    System.out.println("p IS a probable prime number\n");
    }
    }
    else
    {
    System.out.println("p is NOT a Probable Prime Number\n");
    break;
    }
    }

    q = MR.createPrime(512,100);
    System.out.println("q = " + q + "\n");

    for(int i = 1; i <=100; i++)
    {
    if(MR.isProbablePrime(q))
    {
    if(i == 100)
    {
    System.out.println("q IS a probable prime number\n");
    }
    }
    else
    {
    System.out.println("q is NOT a Probable Prime Number\n");
    break;
    }
    }

    }while(p == q);

    BigInteger n = p.multiply(q);//value for n
    BigInteger m = (p.subtract (a)).multiply(q.subtract (b));

    while(E.compareTo(n) != 0)
    {
    E = E.add(BigInteger.ONE);
    gcd = findE.GCD(E,m);//passing val E and m to GCD method
    if(gcd.compareTo(BigInteger.ONE) == 0) break;
    }

    System.out.println("\n" + gcd + "\n");

    do
    {
    BigInteger getD = findD.ExtendedEuclid(E,m,c0,d1,D,f0) //THIS IS THE ERROR HERE, SAYS INCOMPATIBLE TYPES
    D = getD;
    while(D.compareTo(BigInteger.ZERO) < 0)
    {
    D = D.add(m);
    //checking if equation comes out to one
    if(D.multiply(E.mod(m)).compareTo(BigInteger.ONE) == 1)
    {
    System.out.println("\n" + "D Does Equal One: CORRECT!" + "\n");
    }else{
    System.out.println("\n" + "D DOES NOT EQUAL ONE" + "\n");
    }
    }
    }while(D.multiply(E.mod(m)).compareTo(BigInteger.ONE) == 0);

    System.out.println("n = " + n + "\n");//prints value for n
    System.out.println("m = " + m);//prints value for m
    System.out.println("\nE = " + E + "\n");
    System.out.println("D = " + D + "\n");

    String userInput = JOptionPane.showInputDialog("Enter the string to encrypt");



    }

    }

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    The problem is that ExtendedEuclid.ExctendedEuclid() returns a BigInteger[] (an array of big integers), and the in RSA you're trying to assign this to a plain old BigInteger. You can't assign an array of BigIntegers to a single BigInteger, they are different types (hence the error).

    One other thing, method names should start with a lower case, so it would be ExtendedEuclid.extendedEuclid().....
    Also, you shouldn't have a method that has the same name as the class, you'll get very confused between constructors and methods if you do that.

  3. #3
    Join Date
    Jul 2004
    Posts
    7
    Do you know how it can be fixed? I know how to change the names and all that, that was just dumb of me, but do you know how I could make it so I could pass the values to my class?

  4. #4
    Join Date
    Feb 2004
    Posts
    541
    either your method should return one BigInteger instead of an array of them, or you have to change the BigInteger in RSA to an array of BigInteger....ie BigInteger[]

  5. #5
    Join Date
    Jul 2004
    Posts
    7
    Ok, I fixed it, thanks for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center