Exemplo n.º 1
0
    def robust_decode(self, z, encoded):
        x = [self.point(zi).value for zi in z]

        args = [x, encoded, self.d + 1, self.modulus]
        if self.use_omega_powers:
            args += [z, self.point.omega.value, self.point.order]

        decoded, error_poly = gao_interpolate(
            *args, use_omega_powers=self.use_omega_powers)

        if decoded is None:
            return None, None

        errors = []
        if len(error_poly) > 1:
            if self.use_omega_powers:
                err_eval = fft(error_poly, self.point.omega.value,
                               self.modulus, self.point.order)[:self.point.n]
            else:
                x = [self.point(i).value for i in range(self.point.n)]
                err_eval = vandermonde_batch_evaluate(x, [error_poly],
                                                      self.modulus)[0]

            errors = [i for i in range(self.point.n) if err_eval[i] == 0]

        return decoded, errors
Exemplo n.º 2
0
def test_fft():
    # Given
    coeffs = [0, 1]
    p = 13
    omega = 5
    n = 4

    # When
    fft_rep = fft(coeffs, omega, p, n)

    # Then
    assert fft_rep == [1, 5, 12, 8]
Exemplo n.º 3
0
def test_fft_big(galois_field, galois_field_roots):
    # Given
    d = 20
    p = galois_field.modulus
    r = 5
    n = 2**r
    omega = galois_field_roots[r]
    coeffs = [galois_field.random().value for _ in range(d)]

    # When
    fft_rep = fft(coeffs, omega, p, n)

    # Then
    assert len(fft_rep) == n
    for i in range(n):
        x = pow(omega, i, p)
        assert fft_rep[i] == sum(coeffs[j] * pow(x, j, p)
                                 for j in range(d)) % p
Exemplo n.º 4
0
 def encode_one(self, data):
     return fft(data, self.omega, self.modulus, self.order)[:self.n]