Class: Ecc::Curve

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, fp) ⇒ Curve

Returns a new instance of Curve.


7
8
9
10
11
12
13
14
15
# File 'lib/ecc/curve.rb', line 7

def initialize(a, b, fp)
  
  @a = a
  @b = b
  @fp = fp
  
  raise "not elliptic curve" if 4 * (@a ** 3) + 27 * (@b ** 2) == 0
  
end

Instance Attribute Details

#aObject

Returns the value of attribute a


5
6
7
# File 'lib/ecc/curve.rb', line 5

def a
  @a
end

#bObject

Returns the value of attribute b


5
6
7
# File 'lib/ecc/curve.rb', line 5

def b
  @b
end

#fpObject

Returns the value of attribute fp


5
6
7
# File 'lib/ecc/curve.rb', line 5

def fp
  @fp
end

Instance Method Details

#belong?(x, y) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
20
21
# File 'lib/ecc/curve.rb', line 17

def belong?(x,y)
  
  return (y ** 2) % @fp == (x ** 3 + @a * x + @b) % @fp
  
end

#point_order(x, y) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ecc/curve.rb', line 23

def point_order(x, y)
  
  p2 = Point.new(self, x, y)
  
  i = 2
  loop do
    break if p * i == p2
    i += 1
  end
  i
end