Sha256: 0341cd411521e8faf9b1a9be3bac39380216952ab2a4b272becb208506b925b2

Contents?: true

Size: 594 Bytes

Versions: 9

Compression:

Stored size: 594 Bytes

Contents

module Rmega
  module Crypto
    module Rsa
      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

      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
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rmega-0.3.2 lib/rmega/crypto/rsa.rb
rmega-0.3.1 lib/rmega/crypto/rsa.rb
rmega-0.2.7 lib/rmega/crypto/rsa.rb
rmega-0.2.6 lib/rmega/crypto/rsa.rb
rmega-0.2.5 lib/rmega/crypto/rsa.rb
rmega-0.2.4 lib/rmega/crypto/rsa.rb
rmega-0.2.2 lib/rmega/crypto/rsa.rb
rmega-0.2.1 lib/rmega/crypto/rsa.rb
rmega-0.2.0 lib/rmega/crypto/rsa.rb