Class: Ecc::Point

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(curve, x, y) ⇒ Point

Returns a new instance of Point.



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

def initialize(curve, x, y)

  if curve.class != Curve
    raise "1st argument type error"
  end
  
  @curve = curve
  @x = x
  @y = y
  
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/ecc/point.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/ecc/point.rb', line 4

def y
  @y
end

Instance Method Details

#*(d) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ecc/point.rb', line 58

def *(d)
    
  sum = Point.new(@ecc, self)
  
  (d - 1).times do
    sum = sum + self
  end
  
  sum
  
end

#+(other) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ecc/point.rb', line 36

def +(other)
  
  u = Point.new(@ecc, self) if u.class != Point
  v = Point.new(@ecc, other) if v.class != Point
   
  return u if v.zero?
  return v if u.zero?
  
  lambda = nil
    
  if u != v
    lambda = ((v.y - u.y) * (((v.x - u.x) ** (@fp - 2)) % @fp)) % @fp
  else
    lambda = ((3 * u.x ** 2 + @a) * (((2 * u.y) ** (@fp - 2)) % @fp)) % @fp
  end
   
  x3 = lambda ** 2 - u.x - v.x
  y3 = lambda * (u.x - x3) - u.y
  Point.new(@ecc, [x3 % @fp, y3 % @fp])

end

#==(other) ⇒ Object



30
31
32
33
34
# File 'lib/ecc/point.rb', line 30

def ==(other)
  
  @x == other.x and @y == other.y
  
end

#to_sObject



18
19
20
21
22
# File 'lib/ecc/point.rb', line 18

def to_s
    
  "(#{@x}, #{@y})"
  
end

#zero?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/ecc/point.rb', line 24

def zero?
  
  @x == 0 and @y == 0
    
end