Module: Math

Defined in:
lib/aquaticprime.rb

Class Method Summary collapse

Class Method Details

.powmod(x, a, m) ⇒ Object

Calculates x^a mod m. Useful for public key encryption calculations.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aquaticprime.rb', line 20

def self.powmod(x, a, m)
	r = 1
	while a > 0
		if a % 2 == 1
		  r = (r * x) % m
	  end
		a = a >> 1
		x = (x * x) % m
	end
	r
end