org.bouncycastle.pqc.math.ntru.polynomial.test.PolynomialGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-debug-jdk15on Show documentation
Show all versions of bcprov-debug-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 Java 1.5 and later with debug enabled.
package org.bouncycastle.pqc.math.ntru.polynomial.test;
import java.util.Random;
import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial;
public class PolynomialGenerator
{
/**
* Creates a random polynomial with N
coefficients
* between 0
and q-1
.
*
* @param N length of the polynomial
* @param q coefficients will all be below this number
* @return a random polynomial
*/
public static IntegerPolynomial generateRandom(int N, int q)
{
Random rng = new Random();
int[] coeffs = new int[N];
for (int i = 0; i < N; i++)
{
coeffs[i] = rng.nextInt(q);
}
return new IntegerPolynomial(coeffs);
}
}