class Ecc::Point

Attributes

x[RW]
y[RW]

Public Class Methods

new(curve, x, y) click to toggle source
# File lib/ecc/point.rb, line 7
def initialize(curve, x, y)

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

Public Instance Methods

*(d) click to toggle source
# File lib/ecc/point.rb, line 60
def *(d)
    
  sum = self
  
  (d - 1).times do
    sum = sum + self
  end
  
  sum
  
end
+(other) click to toggle source
# File lib/ecc/point.rb, line 37
def +(other)
  
  u = self
  v = other
  
  return u if v.zero?
  return v if u.zero?
  
  t = 0
  
  if u != v
    t = ((v.y - u.y) * (((v.x - u.x) ** (@curve.fp - 2)) % @curve.fp)) % @curve.fp
  else
    t = ((3 * u.x ** 2 + @curve.a) * (((2 * u.y) ** (@curve.fp - 2)) % @curve.fp)) % @curve.fp
  end
   
  x3 = t ** 2 - u.x - v.x
  y3 = t * (u.x - x3) - u.y
  
  Point.new(@curve, x3 % @curve.fp, y3 % @curve.fp)

end
==(other) click to toggle source
# File lib/ecc/point.rb, line 31
def ==(other)
  
  @x == other.x and @y == other.y
  
end
to_s() click to toggle source
# File lib/ecc/point.rb, line 19
def to_s
    
  "(#{@x}, #{@y})"
  
end
zero?() click to toggle source
# File lib/ecc/point.rb, line 25
def zero?
  
  @x == 0 and @y == 0
    
end