referredBlockIndexZZ method

  1. @protected
int referredBlockIndexZZ(
  1. int j1,
  2. int candidatesLength
)

Implementation

@protected
int referredBlockIndexZZ(
  int j1,
  int candidatesLength,
) {
  // In the RFC 9106:
  //   x = J_1^2 / 2^(32)
  //   y = (|W| * x) / 2^(32)
  //   zz = |W| - 1 - y
  final xCarry =
      (((0xFFFF & j1) * j1) + ((0xFFFF0000 & j1) * (0xFFFF & j1))) ~/ _bit32;
  final x = _mask32 & ((j1 >> 16) * (j1 >> 16) + xCarry);
  final yCarry = (((0xFFFF & candidatesLength) * x) +
          ((0xFFFF0000 & candidatesLength) * (0xFFFF & x))) ~/
      _bit32;
  final y = _mask32 & ((candidatesLength >> 16) * (x >> 16) + yCarry);
  return y % candidatesLength;
}