def restore(shares)
      prime = @order
      shares = shares.dup.uniq
      raise "No shares provided" if shares.size == 0
      points = shares.map{|s| point_from_string(s) } # [[m,x,y],...]
      ms = points.map{|p| p[0]}.uniq
      xs = points.map{|p| p[1]}.uniq
      raise "Shares do not use the same M value" if ms.size > 1
      m = ms.first
      raise "All shares must have unique X values" if xs.size != points.size
      raise "Number of shares should be M or more" if points.size < m
      points = points[0, m] # make sure we have exactly M points
      y = 0
      points.size.times do |formula| # 0..(m-1)
        # Multiply the numerator across the top and denominators across the bottom to do Lagrange's interpolation
        numerator = 1
        denominator = 1
        points.size.times do |count| # 0..(m-1)
          if formula != count # skip element with i == j
            startposition = points[formula][1]
            nextposition = points[count][1]
            numerator = (numerator * -nextposition) % prime
            denominator = (denominator * (startposition - nextposition)) % prime
          end
        end
        value = points[formula][2]
        y = (prime + y + (value * numerator * modinv(denominator, prime))) % prime
      end
      return be_from_int(y)
    end
def restore(shares)
      prime = @order
      shares = shares.dup.uniq
      raise "No shares provided" if shares.size == 0
      points = shares.map{|s| point_from_string(s) } # [[m,x,y],...]
      ms = points.map{|p| p[0]}.uniq
      xs = points.map{|p| p[1]}.uniq
      raise "Shares do not use the same M value" if ms.size > 1
      m = ms.first
      raise "All shares must have unique X values" if xs.size != points.size
      raise "Number of shares should be M or more" if points.size < m
      points = points[0, m] # make sure we have exactly M points
      y = 0
      points.size.times do |formula| # 0..(m-1)
        # Multiply the numerator across the top and denominators across the bottom to do Lagrange's interpolation
        numerator = 1
        denominator = 1
        points.size.times do |count| # 0..(m-1)
          if formula != count # skip element with i == j
            startposition = points[formula][1]
            nextposition = points[count][1]
            numerator = (numerator * -nextposition) % prime
            denominator = (denominator * (startposition - nextposition)) % prime
          end
        end
        value = points[formula][2]
        y = (prime + y + (value * numerator * modinv(denominator, prime))) % prime
      end
      return be_from_int(y)
    end
Transforms M 17-byte binary strings into original secret 16-byte binary string.
 Each share string must be well-formed.