Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PolynomialGenerator.java « test « polynomial « ntru « math « pqc « spongycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a30fea4d3e7f1b48db3bfb22b2fe4b91021ce58a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package org.spongycastle.pqc.math.ntru.polynomial.test;

import java.util.Random;

import org.spongycastle.pqc.math.ntru.polynomial.IntegerPolynomial;

public class PolynomialGenerator
{
    /**
     * Creates a random polynomial with <code>N</code> coefficients
     * between <code>0</code> and <code>q-1</code>.
     *
     * @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);
    }
}