Cryptography Reference
In-Depth Information
if (maxModulusBitLength!=other.maxModulusBitLength) throw new
IllegalArgumentException
(“IntCRT objects must have same modulus bit length to be multiplied together”);
long[] answer=new long[residues.length];
//Multiply i-th residue of this by i-th residue of other, may produce a long
//Take residue mod i-th moduli
for (int i=0;i<residues.length;i++)
answer[i]=(residues[i]*other.residues[i])%moduli[i];
return new IntCRT(answer);
}
The toString() method takes the residues and moduli, and “recomposes” the BigInteger
using the solveCRT() method from the BigIntegerMath class. We then convert it to a string
by calling the toString() method from the BigInteger class.
public String toString() {
//Make an array of BigIntegers for each modulus
BigInteger[] m=new BigInteger[moduli.length];
//We reconstruct a BigInteger from the residues by using the Chinese Remainder
//Theorem
for (int i=0;i<moduli.length;i++) m[i]=BigInteger.valueOf(moduli[i]);
//Make an array of BigIntegers for each residue
BigInteger[] r=new BigInteger[residues.length];
for (int i=0;i<residues.length;i++) r[i]=BigInteger.valueOf(residues[i]);
//Reconstruct the BigInteger and return it as a string
BigInteger whopper=BigIntegerMath.solveCRT(r,m)[0];
return whopper.toString();
}
}//End of IntCRT class
Figures 16.2, 16.3, and 16.4 are shots of TestIntCRTApplet.
FIGURE 16.2
Search WWH ::




Custom Search