public static List<BigInteger> partitionBits(BigInteger value,int partitionSize,BigInteger mask) throws PIRException {
  if (mask.bitLength() != partitionSize) {
    throw new PIRException("mask.bitLength() " + mask.bitLength() + " != partitionSize = "+ partitionSize);
  }
  List<BigInteger> partitions=new ArrayList<>();
  if (value.bitLength() < partitionSize) {
    partitions.add(value);
  }
 else {
    int bitLength=value.bitLength();
    mask=mask.shiftLeft(bitLength - partitionSize);
    int partNum=0;
    for (int i=0; i < bitLength; i+=partitionSize) {
      BigInteger result=value.and(mask);
      int shiftSize=bitLength - (partNum + 1) * partitionSize;
      if (shiftSize < 0) {
        shiftSize=0;
      }
      result=result.shiftRight(shiftSize);
      mask=mask.shiftRight(partitionSize);
      partitions.add(result);
      ++partNum;
    }
  }
  return partitions;
}

public static List < BigInteger > partitionBits ( BigInteger value , int partitionSize , BigInteger mask ) throws PIRException { if ( mask . bitLength ( ) != partitionSize ) { throw new PIRException ( "mask.bitLength() " + mask . bitLength ( ) + " != partitionSize = " + partitionSize ) ; } List < BigInteger > partitions = new ArrayList < > ( ) ; if ( value . bitLength ( ) < partitionSize ) { partitions . add ( value ) ; } else { int bitLength = value . bitLength ( ) ; mask = mask . shiftLeft ( bitLength - partitionSize ) ; int partNum = 0 ; for ( int i = 0 ; i < bitLength ; i += partitionSize ) { BigInteger result = value . and ( mask ) ; int shiftSize = bitLength - ( partNum + 1 ) * partitionSize ; if ( shiftSize < 0 ) { shiftSize = 0 ; } result = result . shiftRight ( shiftSize ) ; mask = mask . shiftRight ( partitionSize ) ; partitions . add ( result ) ; ++ partNum ; } } return partitions ; }
splits the given biginteger into partitions given by the partitionsize .
