Module: Crypto_math

Included in:
Bignum, Fixnum
Defined in:
lib/openid/util.rb

Overview

Functions convenient for cryptography

Instance Method Summary collapse

Instance Method Details

#mod_exp(n, q) ⇒ Object

by Eric Lee Green. x.mod_exp(n,q) returns x ** n % q



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/openid/util.rb', line 12

def mod_exp(n,q)
  counter=0
  n_p=n  # N 

  y_p=1        # Y

  z_p=self  # Z

  while n_p != 0
        if n_p[0]==1
      y_p=(y_p*z_p) % q
        end
        n_p = n_p >> 1  
        z_p = (z_p * z_p) % q
        counter += 1
    end
    return y_p
end