Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.bouncycastle.pqc.math.ntru.euclid;

Extended Euclidean Algorithm in ints
 
 public class IntEuclidean
 {
     public int xygcd;
 
    private IntEuclidean()
    {
    }

    
Runs the EEA on two ints
Implemented from pseudocode on Wikipedia.

Parameters:
a
b
Returns:
a IntEuclidean object that contains the result in the variables x, y, and gcd
    public static IntEuclidean calculate(int aint b)
    {
        int x = 0;
        int lastx = 1;
        int y = 1;
        int lasty = 0;
        while (b != 0)
        {
            int quotient = a / b;
            int temp = a;
            a = b;
            b = temp % b;
            temp = x;
            x = lastx - quotient * x;
            lastx = temp;
            temp = y;
            y = lasty - quotient * y;
            lasty = temp;
        }
        IntEuclidean result = new IntEuclidean();
        result.x = lastx;
        result.y = lasty;
        result.gcd = a;
        return result;
    }
New to GrepCode? Check out our FAQ X