Class: EllipticCurve::Curve::CurveFp
- Inherits:
-
Object
- Object
- EllipticCurve::Curve::CurveFp
- Defined in:
- lib/curve.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#g ⇒ Object
Returns the value of attribute g.
-
#n ⇒ Object
Returns the value of attribute n.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nistName ⇒ Object
Returns the value of attribute nistName.
-
#oid ⇒ Object
Returns the value of attribute oid.
-
#p ⇒ Object
Returns the value of attribute p.
Instance Method Summary collapse
- #contains(p) ⇒ Object
-
#initialize(a, b, p, n, gx, gy, name, oid, nistName = nil) ⇒ CurveFp
constructor
A new instance of CurveFp.
- #length ⇒ Object
- #y(x, isEven) ⇒ Object
Constructor Details
#initialize(a, b, p, n, gx, gy, name, oid, nistName = nil) ⇒ CurveFp
Returns a new instance of CurveFp.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/curve.rb', line 11 def initialize(a, b, p, n, gx, gy, name, oid, nistName=nil) @a = a @b = b @p = p @n = n @g = Point.new(gx, gy) @name = name @oid = oid @nistName = nistName end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
9 10 11 |
# File 'lib/curve.rb', line 9 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
9 10 11 |
# File 'lib/curve.rb', line 9 def b @b end |
#g ⇒ Object
Returns the value of attribute g.
9 10 11 |
# File 'lib/curve.rb', line 9 def g @g end |
#n ⇒ Object
Returns the value of attribute n.
9 10 11 |
# File 'lib/curve.rb', line 9 def n @n end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/curve.rb', line 9 def name @name end |
#nistName ⇒ Object
Returns the value of attribute nistName.
9 10 11 |
# File 'lib/curve.rb', line 9 def nistName @nistName end |
#oid ⇒ Object
Returns the value of attribute oid.
9 10 11 |
# File 'lib/curve.rb', line 9 def oid @oid end |
#p ⇒ Object
Returns the value of attribute p.
9 10 11 |
# File 'lib/curve.rb', line 9 def p @p end |
Instance Method Details
#contains(p) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/curve.rb', line 22 def contains(p) # Verify if the point `p` is on the curve # :param p: point p = Point(x, y) # :return: boolean if not (0 <= p.x and p.x <= @p - 1) return false end if not (0 <= p.y and p.y <= @p - 1) return false end if (p.y ** 2 - (p.x ** 3 + @a * p.x + @b)) % @p != 0 return false end return true end |
#length ⇒ Object
38 39 40 |
# File 'lib/curve.rb', line 38 def length return (1 + ("%x" % @n).length).div(2) end |
#y(x, isEven) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/curve.rb', line 42 def y(x, isEven) ySquared = (x.pow(3, @p) + @a * x + @b) % @p y = Math::modularSquareRoot(ySquared, @p) if isEven != (y % 2 == 0) y = @p - y end return y end |