All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.pqc.math.ntru.euclid.IntEuclidean Maven / Gradle / Ivy

There is a newer version: 1.70_1
Show newest version
package org.bouncycastle.pqc.math.ntru.euclid;

/**
 * Extended Euclidean Algorithm in ints
 */
public class IntEuclidean
{
    public int x, y, gcd;

    private IntEuclidean()
    {
    }

    /**
     * Runs the EEA on two ints
* Implemented from pseudocode on Wikipedia. * * @param a * @param b * @return a IntEuclidean object that contains the result in the variables x, y, and gcd */ public static IntEuclidean calculate(int a, int 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; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy