DataWord implements Comparable<DataWord> { public void mod(DataWord word) { if (word.isZero()) { this.and(ZERO); return; } BigInteger result = value().mod(word.value()); this.data = ByteUtil.copyToArray(result.and(MAX_VALUE)); } DataWord();  DataWord(int num);  DataWord(long num);  DataWord(byte[] data); byte[] getData(); byte[] getNoLeadZeroesData(); byte[] getLast20Bytes(); BigInteger value(); int intValue(); long longValue(); BigInteger sValue(); boolean isZero(); boolean isNegative(); DataWord and(DataWord w2); DataWord or(DataWord w2); DataWord xor(DataWord w2); void negate(); void add(DataWord word); void add2(DataWord word); void mul(DataWord word); void div(DataWord word); void sDiv(DataWord word); void sub(DataWord word); void exp(DataWord word); void mod(DataWord word); void sMod(DataWord word); void addmod(DataWord word1, DataWord word2); void mulmod(DataWord word1, DataWord word2); String toString(); String shortHex(); DataWord clone(); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(DataWord o); static final BigInteger _2_256; static final BigInteger MAX_VALUE; static final DataWord ZERO; static final DataWord ZERO_EMPTY_ARRAY; }
@Test public void testMod() { String expected = "000000000000000000000000000000000000000000000000000000000000001a"; byte[] one = new byte[32]; one[31] = 0x1e; byte[] two = new byte[32]; for (int i = 0; i < two.length; i++) { two[i] = (byte) 0xff; } two[31] = 0x56; DataWord x = new DataWord(one); DataWord y = new DataWord(two); y.mod(x); assertEquals(32, y.getData().length); assertEquals(expected, Hex.toHexString(y.getData())); }