pub fn reconstruct(&self, indices: &[u32], shares: &[F::E]) -> Vec<F::E> {
        assert!(shares.len() == indices.len());
        assert!(shares.len() >= self.reconstruct_limit());
        if shares.len() == self.share_count {
            // we're in the special case where we can use the FFTs for interpolation
            let mut values = shares.to_vec();
            values.insert(0, self.field.zero());
            ::numtheory::fft::fft3_inverse(&self.field, &mut values, &self.omega_shares);
            let mut coefficients = values.into_iter()
                .take(self.reconstruct_limit() + 1)
                .collect::<Vec<_>>();
            ::numtheory::fft::fft2(&self.field, &mut coefficients, &self.omega_secrets);
            let secrets = coefficients.into_iter()
                .skip(1)
                .take(self.secret_count)
                .collect();
                // TODO replace with truncate
            secrets
        } else {
            // we cannot use the FFT so default to Newton interpolation
            let mut points: Vec<F::E> = indices.iter()
                .map(|x| self.field.pow(&self.omega_shares, x + 1))
                .collect();
            let mut values = shares.to_vec();
            // insert missing value for point 1 (zero)
            points.insert(0, self.field.one());
            values.insert(0, self.field.zero());
            // interpolate using Newton's method
            // TODO optimise by using Newton-equally-space variant
            let poly = ::numtheory::NewtonPolynomial::compute(&points, &values, &self.field);
            // evaluate at omega_secrets points to recover secrets
            // TODO optimise to avoid re-computation of power
            let secrets = (1..self.reconstruct_limit())
                .map(|e| self.field.pow(&self.omega_secrets, e as u32))
                .map(|point| poly.evaluate(&point, &self.field))
                .take(self.secret_count)
                .collect();
            secrets
        }
    }
/// Reconstruct the secrets from a large enough subset of the shares.
///
/// `indices` are the ranks of the known shares as output by the `share` method,
///  while `values` are the actual values of these shares.
/// Both must have the same number of elements, and at least `reconstruct_limit`.
///
/// The resulting vector is of length `secret_count`.
Reconstruct the secrets from a large enough subset of the shares.

The resulting vector is of length `secret_count`.
Reconstruct the secrets from a large enough subset of the shares . The resulting vector is of length ` secret_count ` .
pub fn reconstruct(&self, indices: &[u32], shares: &[F::E]) -> Vec<F::E> {
        assert!(shares.len() == indices.len());
        assert!(shares.len() >= self.reconstruct_limit());
        if shares.len() == self.share_count {
            // we're in the special case where we can use the FFTs for interpolation
            let mut values = shares.to_vec();
            values.insert(0, self.field.zero());
            ::numtheory::fft::fft3_inverse(&self.field, &mut values, &self.omega_shares);
            let mut coefficients = values.into_iter()
                .take(self.reconstruct_limit() + 1)
                .collect::<Vec<_>>();
            ::numtheory::fft::fft2(&self.field, &mut coefficients, &self.omega_secrets);
            let secrets = coefficients.into_iter()
                .skip(1)
                .take(self.secret_count)
                .collect();
                // TODO replace with truncate
            secrets
        } else {
            // we cannot use the FFT so default to Newton interpolation
            let mut points: Vec<F::E> = indices.iter()
                .map(|x| self.field.pow(&self.omega_shares, x + 1))
                .collect();
            let mut values = shares.to_vec();
            // insert missing value for point 1 (zero)
            points.insert(0, self.field.one());
            values.insert(0, self.field.zero());
            // interpolate using Newton's method
            // TODO optimise by using Newton-equally-space variant
            let poly = ::numtheory::NewtonPolynomial::compute(&points, &values, &self.field);
            // evaluate at omega_secrets points to recover secrets
            // TODO optimise to avoid re-computation of power
            let secrets = (1..self.reconstruct_limit())
                .map(|e| self.field.pow(&self.omega_secrets, e as u32))
                .map(|point| poly.evaluate(&point, &self.field))
                .take(self.secret_count)
                .collect();
            secrets
        }
    }
pub fn reconstruct ( & self , indices : & [ u32 ] , shares : & [ F :: E ] ) -> Vec < F :: E > { assert ! ( shares len ( ) indices len ( ) ) ; assert ! ( shares len ( ) self reconstruct_limit ( ) ) ; if shares . len ( ) == self . share_count { // we're in the special case where we can use the FFTs for interpolation let mut values = shares . to_vec ( ) ; values . insert ( 0 , self . field . zero ( ) ) ; :: numtheory :: fft :: fft3_inverse ( & self . field , & mut values , & self . omega_shares ) ; let mut coefficients = values . into_iter ( ) . take ( self . reconstruct_limit ( ) + 1 ) . collect :: < Vec < _ > > ( ) ; :: numtheory :: fft :: fft2 ( & self . field , & mut coefficients , & self . omega_secrets ) ; let secrets = coefficients . into_iter ( ) . skip ( 1 ) . take ( self . secret_count ) . collect ( ) ; // TODO replace with truncate secrets } else { // we cannot use the FFT so default to Newton interpolation let mut points : Vec < F :: E > = indices . iter ( ) . map ( | x | self . field . pow ( & self . omega_shares , x + 1 ) ) . collect ( ) ; let mut values = shares . to_vec ( ) ; // insert missing value for point 1 (zero) points . insert ( 0 , self . field . one ( ) ) ; values . insert ( 0 , self . field . zero ( ) ) ; // interpolate using Newton's method // TODO optimise by using Newton-equally-space variant let poly = :: numtheory :: NewtonPolynomial :: compute ( & points , & values , & self . field ) ; // evaluate at omega_secrets points to recover secrets // TODO optimise to avoid re-computation of power let secrets = ( 1 .. self . reconstruct_limit ( ) ) . map ( | e | self . field . pow ( & self . omega_secrets , e as u32 ) ) . map ( | point | poly . evaluate ( & point , & self . field ) ) . take ( self . secret_count ) . collect ( ) ; secrets } }
Reconstruct the secrets from a large enough subset of the shares.
Reconstruct the secrets from a large enough subset of the shares .
&self
indices
&[u32]
shares
&[F::E]