int perturbationBases = params.B;
NTRUSigningPrivateKeyParameters kPriv = kp;
NTRUSigningPublicKeyParameters kPub = kp.getPublicKey();
IntegerPolynomial s = new IntegerPolynomial(N);
int iLoop = perturbationBases;
while (iLoop >= 1)
{
Polynomial f = kPriv.getBasis(iLoop).f;
Polynomial fPrime = kPriv.getBasis(iLoop).fPrime;
IntegerPolynomial y = f.mult(i);
y.div(q);
y = fPrime.mult(y);
IntegerPolynomial x = fPrime.mult(i);
x.div(q);
x = f.mult(x);
IntegerPolynomial si = y;
si.sub(x);
s.add(si);
IntegerPolynomial hi = (IntegerPolynomial)kPriv.getBasis(iLoop).h.clone();
if (iLoop > 1)
{
hi.sub(kPriv.getBasis(iLoop - 1).h);
}
else
{
hi.sub(kPub.h);
}
i = si.mult(hi, q);
iLoop--;
}
Polynomial f = kPriv.getBasis(0).f;
Polynomial fPrime = kPriv.getBasis(0).fPrime;
IntegerPolynomial y = f.mult(i);
y.div(q);
y = fPrime.mult(y);
IntegerPolynomial x = fPrime.mult(i);
x.div(q);
x = f.mult(x);
y.sub(x);
s.add(y);
s.modPositive(q);