Search code examples
javabigintegerxor

How to break the 2048bit BigInteger into words with a fixed number of 64 bits?


I have a key that contain 2048 bit BigInteger number. I want to break it into words with a fixed number of 64 bits, and then computes the exclusive OR of all those words; does anyone can help me to implement this by java? this is my method that must be implemented:

public static BigInteger parityWordChecksum(BigInteger key) {
//result is a 64 bit integer
    return result;
}

Solution

  • LongBuffer buffer = ByteBuffer.wrap(myBigInteger.toByteArray()).asLongBuffer();
    long xor = 0;
    while (buffer.hasRemaining()) {
      xor ^= buffer.get();
    }
    return BigInteger.valueOf(xor);