Module: MTProto::Crypto::Factorization

Defined in:
lib/mtproto/crypto/factorization.rb

Class Method Summary collapse

Class Method Details

.bytes_to_integer(bytes) ⇒ Object



20
21
22
# File 'lib/mtproto/crypto/factorization.rb', line 20

def bytes_to_integer(bytes)
  bytes.unpack('C*').inject(0) { |sum, byte| (sum << 8) | byte }
end

.factorize_pq(pq_bytes) ⇒ Object



16
17
18
# File 'lib/mtproto/crypto/factorization.rb', line 16

def factorize_pq(pq_bytes)
  FactorizationExt.factorize_pq(pq_bytes)
end

.integer_sqrt(n) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mtproto/crypto/factorization.rb', line 24

def integer_sqrt(n)
  return n if n < 2

  x = n
  y = (x + 1) / 2

  while y < x
    x = y
    y = (x + n / x) / 2
  end

  x
end