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

org.spongycastle.math.ntru.euclid.IntEuclidean Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.7.

There is a newer version: 1.47.0.3
Show newest version
package org.spongycastle.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