Module: Rmega::Crypto::Rsa
- Included in:
- Rmega::Crypto
- Defined in:
- lib/rmega/crypto/rsa.rb
Instance Method Summary collapse
Instance Method Details
#powm(b, p, m) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/rmega/crypto/rsa.rb', line 4 def powm(b, p, m) if p == 1 b % m elsif (p & 0x1) == 0 t = powm(b, p >> 1, m) (t * t) % m else (b * powm(b, p-1, m)) % m end end |
#rsa_decrypt(m, pqdu) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rmega/crypto/rsa.rb', line 15 def rsa_decrypt(m, pqdu) p, q, d, u = pqdu if p && q && u m1 = powm(m, d % (p - 1), p) m2 = powm(m, d % (q - 1), q) h = m2 - m1 h = h + q if h < 0 h = h * u % q h * p + m1 else pow_m(m, d, p * q) end end |