Top Level Namespace

Defined Under Namespace

Classes: MR_Prime, Numeric

Instance Method Summary collapse

Instance Method Details

#exponent_mod(base, exponent, modulus) ⇒ Object

Thanks Bruce Schneier for this gem



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/mr_prime/mr_prime_rb.rb', line 2

def exponent_mod(base,exponent,modulus)
  result = 1;
  while(exponent > 0) 
    if ((exponent & 1) == 1) 
      result = (result * base) % modulus;
    end
    exponent >>= 1;
    base = (base * base) % modulus;
  end

  return result;
end