Class: Mathematics

Inherits:
Object
  • Object
show all
Defined in:
lib/mathematics.rb

Constant Summary collapse

LIMIT =
10000

Class Method Summary collapse

Class Method Details

.func_totiente_n(p, q) ⇒ Object



41
42
43
44
45
# File 'lib/mathematics.rb', line 41

def self.func_totiente_n(p, q)
  # função totiente em n
  # 𝜑(𝑛) = (𝑝 − 1) ∗ (𝑞 − 1)
  (p - 1) * (q - 1)
end

.is_multiplicative_inverse?(term1, term2) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/mathematics.rb', line 36

def self.is_multiplicative_inverse?(term1, term2)
  # (i * e) % @totiente_n == 1
  mod(term1, term2) == 1
end

.mod(dividend, divider) ⇒ Object



32
33
34
# File 'lib/mathematics.rb', line 32

def self.mod(dividend, divider)
  dividend % divider
end

.pow(n, e) ⇒ Object



28
29
30
# File 'lib/mathematics.rb', line 28

def self.pow(n, e)
  n ** e
end

.random_primeObject



23
24
25
26
# File 'lib/mathematics.rb', line 23

def self.random_prime
  number_random = rand(@number_primes.length)
  @number_primes[number_random]
end