Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有x^n–;1._Java_Cryptography_Polynomials_Ntrusign - Fatal编程技术网

Java 具有x^n–;1.

Java 具有x^n–;1.,java,cryptography,polynomials,ntrusign,Java,Cryptography,Polynomials,Ntrusign,具有x^n–1(mod p)的多项式的结式 我正在实施第2.2.7.1节所述的NTRUSign算法,该算法涉及计算多项式的结果。我得到的结果向量为零,这显然是不正确的 private static CompResResult compResMod(IntegerPolynomial f, int p) { int N = f.coeffs.length; IntegerPolynomial a = new IntegerPolynomial(N); a.coeffs[0]

具有x^n–1(mod p)的多项式的结式

我正在实施第2.2.7.1节所述的NTRUSign算法,该算法涉及计算多项式的结果。我得到的结果向量为零,这显然是不正确的

private static CompResResult compResMod(IntegerPolynomial f, int p) {
    int N = f.coeffs.length;
    IntegerPolynomial a = new IntegerPolynomial(N);
    a.coeffs[0] = -1;
    a.coeffs[N-1] = 1;
    IntegerPolynomial b = new IntegerPolynomial(f.coeffs);
    IntegerPolynomial v1 = new IntegerPolynomial(N);
    IntegerPolynomial v2 = new IntegerPolynomial(N);
    v2.coeffs[0] = 1;
    int da = a.degree();
    int db = b.degree();
    int ta = da;
    int c = 0;
    int r = 1;
    while (db > 0) {
        c = invert(b.coeffs[db], p);
        c = (c * a.coeffs[da]) % p;

        IntegerPolynomial cb = b.clone();
        cb.mult(c);
        cb.shift(da - db);
        a.sub(cb, p);

        IntegerPolynomial v2c = v2.clone();
        v2c.mult(c);
        v2c.shift(da - db);
        v1.sub(v2c, p);

        if (a.degree() < db) {
            r *= (int)Math.pow(b.coeffs[db], ta-a.degree());
            r %= p;
            if (ta%2==1 && db%2==1)
                r = (-r) % p;
            IntegerPolynomial temp = a;
            a = b;
            b = temp;
            temp = v1;
            v1 = v2;
            v2 = temp;
            ta = db;
        }
        da = a.degree();
        db = b.degree();
    }
    r *= (int)Math.pow(b.coeffs[0], da);
    r %= p;
    c = invert(b.coeffs[0], p);
    v2.mult(c);
    v2.mult(r);
    v2.mod(p);
    return new CompResResult(v2, r);
}
private static compresult compResMod(整数多项式f,int p){
int N=f系数长度;
积分多项式a=新的积分多项式(N);
a、 系数[0]=-1;
a、 系数[N-1]=1;
积分多项式b=新的积分多项式(f系数);
整数多项式v1=新整数多项式(N);
整数多项式v2=新整数多项式(N);
v2.系数[0]=1;
int da=a.度();
int db=b.degree();
int-ta=da;
int c=0;
int r=1;
而(db>0){
c=反向(b.系数[db],p);
c=(c*a.coefs[da])%p;
整数多项式cb=b.clone();
cb.mult(c);
cb.shift(da-db);
a、 副主席(cb,p);
整数多项式v2c=v2.clone();
v2c.mult(c);
v2c.位移(da-db);
v1.sub(v2c,p);
如果(a.度()
有一些伪代码看起来非常相似

为什么我的代码不起作用? 是否有中间结果我可以检查


我没有发布整数多项式代码,因为它不太有趣,而且我已经通过了单元测试。compressResult只是一个简单的“Java结构”。

我猜(int)Math.pow(b.coefs[0],da)的计算结果是0。如果您尝试使用调试器单步执行此代码,它应该会告诉您每次值为零的原因。

我猜(int)Math.pow(b.coefs[0],da)的计算结果为0。如果您尝试用调试器来遍历此代码,它应该每次显示您的值为何为零。由于类是泛型的,
多项式
可以简化实现。在测试中使用了<代码>多项式>代码>。

< P>作为一种选择,考虑类。由于类是泛型的,
多项式
可以简化实现。这使用了
多项式
以方便测试。

谢谢,这让我走上了正确的道路。通过将代码与JScience结果进行比较,我能够使代码正常工作。谢谢,这让我走上了正确的轨道。通过将代码与JScience结果进行比较,我能够使代码正常工作。