org.bouncycastle.pqc.math.ntru.euclid.IntEuclidean Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk15on Show documentation
Show all versions of bcprov-jdk15on Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 and up.
The newest version!
package org.bouncycastle.pqc.math.ntru.euclid;
/**
* Extended Euclidean Algorithm in int
s
*/
public class IntEuclidean
{
public int x, y, gcd;
private IntEuclidean()
{
}
/**
* Runs the EEA on two int
s
* 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