Function modInv

  • Find modular inverse of a (mod b).

    Parameters

    • a: number

      Number to find modular inverse of.

    • b: number

      Modulus.

    • strict: boolean = true

      Ensure that a * modInv(a, b) = 1 (mod b). If strict = false we have a * modInv(a, b) = gdc(a, b) (mod b) instead.

    Returns number

    The modular inverse in the range {0, 1, ..., b - 1}.