ph-math/src/main/java/com/helger/numbercruncher/mathutils/ModuloArithmetic.java
public static int multiply (final int pa, final int pb, final int m)
  {
    int a = pa;
    int b = pb;
    int product = 0;

    // Loop to compute product = (a*b)%m.
    while (a > 0)
    {

      // Does the rightmost bit of a == 1?
      if ((a & 1) == 1)
      {
        product += b;
        product %= m;
      }

      // Double b modulo m, and
      // shift a 1 bit to the right.
      b <<= 1;
      b %= m;
      a >>= 1;
    }

    return product;
  }
public static int multiply (final int pa, final int pb, final int m)
  {
    int a = pa;
    int b = pb;
    int product = 0;

    // Loop to compute product = (a*b)%m.
    while (a > 0)
    {

      // Does the rightmost bit of a == 1?
      if ((a & 1) == 1)
      {
        product += b;
        product %= m;
      }

      // Double b modulo m, and
      // shift a 1 bit to the right.
      b <<= 1;
      b %= m;
      a >>= 1;
    }

    return product;
  }
Multiply two integer values a and b modulo m.

@param pa
the value of a
@param pb
the value of b
@param m
the modulus m
@return the value of ab (mod m)