Module: BLS::FQP
Overview
Module for a field over polynomial. TT - ThisType, CT - ChildType, TTT - Tuple Type
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add(other) ⇒ Object (also: #+)
- #conjugate ⇒ Object
- #div(other) ⇒ Object (also: #/)
- #negate ⇒ Object
- #pow(n) ⇒ Object (also: #**)
- #subtract(other) ⇒ Object (also: #-)
-
#to_bytes ⇒ String
Convert to byte string.
-
#to_hex ⇒ String
Convert to hex string.
- #zero? ⇒ Boolean
Instance Method Details
#==(other) ⇒ Object
124 125 126 |
# File 'lib/bls/field.rb', line 124 def ==(other) coeffs == other.coeffs end |
#add(other) ⇒ Object Also known as: +
132 133 134 |
# File 'lib/bls/field.rb', line 132 def add(other) self.class.new(coeffs.map.with_index { |v, i| v + other.coeffs[i] }) end |
#conjugate ⇒ Object
168 169 170 |
# File 'lib/bls/field.rb', line 168 def conjugate self.class.new([coeffs[0], coeffs[1].negate]) end |
#div(other) ⇒ Object Also known as: /
142 143 144 145 |
# File 'lib/bls/field.rb', line 142 def div(other) inv = other.is_a?(Integer) ? Fp.new(other).invert.value : other.invert multiply(inv) end |
#negate ⇒ Object
148 149 150 |
# File 'lib/bls/field.rb', line 148 def negate self.class.new(coeffs.map(&:negate)) end |
#pow(n) ⇒ Object Also known as: **
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/bls/field.rb', line 152 def pow(n) one = self.class.const_get(:ONE) return one if n.zero? return self if n == 1 p = one d = self while n.positive? p *= d unless (n & 1).zero? n >>= 1 d = d.square end p end |
#subtract(other) ⇒ Object Also known as: -
137 138 139 |
# File 'lib/bls/field.rb', line 137 def subtract(other) self.class.new(coeffs.map.with_index { |v, i| v - other.coeffs[i] }) end |
#to_bytes ⇒ String
Convert to byte string.
174 175 176 |
# File 'lib/bls/field.rb', line 174 def to_bytes [to_hex].pack('H*') end |
#to_hex ⇒ String
Convert to hex string.
180 181 182 |
# File 'lib/bls/field.rb', line 180 def to_hex coeffs.map(&:to_hex).join end |
#zero? ⇒ Boolean
128 129 130 |
# File 'lib/bls/field.rb', line 128 def zero? coeffs.find { |c| !c.zero? }.nil? end |