Class: Ecc::Point
- Inherits:
-
Object
- Object
- Ecc::Point
- Defined in:
- lib/ecc/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #*(d) ⇒ Object
- #+(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(curve, x, y) ⇒ Point
constructor
A new instance of Point.
- #to_s ⇒ Object
- #zero? ⇒ Boolean
Constructor Details
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/ecc/point.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/ecc/point.rb', line 5 def y @y end |
Instance Method Details
#*(d) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ecc/point.rb', line 60 def *(d) sum = self (d - 1).times do sum = sum + self end sum end |
#+(other) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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) ⇒ Object
31 32 33 34 35 |
# File 'lib/ecc/point.rb', line 31 def ==(other) @x == other.x and @y == other.y end |
#to_s ⇒ Object
19 20 21 22 23 |
# File 'lib/ecc/point.rb', line 19 def to_s "(#{@x}, #{@y})" end |
#zero? ⇒ Boolean
25 26 27 28 29 |
# File 'lib/ecc/point.rb', line 25 def zero? @x == 0 and @y == 0 end |