public static Polynomial berlekampMassey(final Sequence seq) {
        final int n = seq.getLength();
        Polynomial C = new Polynomial(1);
        Polynomial B = new Polynomial(1);
        int x = 1;
        int L = 0;
        int b = 1;
        int N = 0;
        while(N != n) {
            int temp = 0;
            for(int i = 1; i <= L; i++) {
                temp += C.getCoeff(i) * seq.getElement(N - i);
                temp = temp % 2;
            }
            final int d = (seq.getElement(N) + temp) % 2;
            if(d == 0) {
                x += 1;
            } else if(2 * L > N) {
                if(d * b == 1) {
                    C = PolynomialUtils.sum(C, PolynomialUtils.product(B, new Polynomial(1 << x)));
                }
                //C=C-db^-1X^xB
                x += 1;
            } else {
                final Polynomial T = C;
                if(d * b == 1) {
                    C = PolynomialUtils.sum(C, PolynomialUtils.product(B, new Polynomial(1 << x)));
                }
                //C=C-db^-1X^xB
                L = N + 1 - L;
                B = T;
                b = d;
                x = 1;
            }
            N++;
        }
        return new Polynomial(BinaryUtils.reverse(C.toInt(), C.getDegree() + 1));
    }