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
132 133 134 |
# File 'lib/bls/field.rb', line 132 def ==(other) coeffs == other.coeffs end |
#add(other) ⇒ Object Also known as: +
140 141 142 |
# File 'lib/bls/field.rb', line 140 def add(other) self.class.new(coeffs.map.with_index { |v, i| v + other.coeffs[i] }) end |
#conjugate ⇒ Object
176 177 178 |
# File 'lib/bls/field.rb', line 176 def conjugate self.class.new([coeffs[0], coeffs[1].negate]) end |
#div(other) ⇒ Object Also known as: /
150 151 152 153 |
# File 'lib/bls/field.rb', line 150 def div(other) inv = other.is_a?(Integer) ? Fp.new(other).invert.value : other.invert multiply(inv) end |
#negate ⇒ Object
156 157 158 |
# File 'lib/bls/field.rb', line 156 def negate self.class.new(coeffs.map(&:negate)) end |
#pow(n) ⇒ Object Also known as: **
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/bls/field.rb', line 160 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: -
145 146 147 |
# File 'lib/bls/field.rb', line 145 def subtract(other) self.class.new(coeffs.map.with_index { |v, i| v - other.coeffs[i] }) end |
#to_bytes ⇒ String
Convert to byte string.
182 183 184 |
# File 'lib/bls/field.rb', line 182 def to_bytes [to_hex].pack('H*') end |
#to_hex ⇒ String
Convert to hex string.
188 189 190 |
# File 'lib/bls/field.rb', line 188 def to_hex coeffs.map(&:to_hex).join end |
#zero? ⇒ Boolean
136 137 138 |
# File 'lib/bls/field.rb', line 136 def zero? coeffs.find { |c| !c.zero? }.nil? end |