Module: TTCrypt

Defined in:
lib/ttcrypt.rb,
lib/ttcrypt.rb,
lib/ttcrypt/version.rb,
ext/ttcrypt/ttcrypt_ruby.cpp

Overview

Thrift cryptographics primitives: fast c++ implementation, only strong schemes, releases GVL on long operations so other threads can be executed in parallel.

Defined Under Namespace

Classes: RsaKey

Constant Summary collapse

VERSION =
'0.0.7'

Class Method Summary collapse

Class Method Details

._factorizeObject

._generate_primeObject

.factorize(composite) ⇒ int

Pollard ‘rho’ prime factorization. Allows execution of other ruby threads in parallel (releases GVL)

Returns:

  • (int)

    array of prime factors



10
11
12
13
14
# File 'lib/ttcrypt.rb', line 10

def factorize composite
  hex = composite.to_i.to_s(16)
  hex = '0' + hex if (hex.length & 1) == 1
  _factorize(hex).map { |x| x.to_i(16) }
end

.generate_prime(bits) ⇒ Object

Generate random probable prime number with a given bits length. This implementation will generate prime such as 2^(bits-1) < prime < 2 ^ bits.



19
20
21
# File 'lib/ttcrypt.rb', line 19

def generate_prime bits
  _generate_prime(bits).to_i(16)
end