@SuppressWarnings("empty-statement")
    public static String berlekamp_massey(int[] array) {
        String s = new String();
        String suc = new String();
        final int N = array.length;
        int[] b = new int[N];
        int[] c = new int[N];
        int[] t = new int[N];
        int cont = 0;
        
        b[0] = 1;
        c[0] = 1;
        int l = 0;
        int m = -1;
        for (int n = 0; n < N; n++) {
            int d = 0;
            for (int i = 0; i <= l; i++) {
                d ^= c[i] * array[n - i];
            }
            if (d == 1) {
                System.arraycopy(c, 0, t, 0, N);
                for (int j = 0; j< (N-(n-m)); j++) {
                    c[((n-m)+j)] ^= b[j];
                }
                if (l <= n / 2) {
                    l = n + 1 - l;
                    m = n;
                    System.arraycopy(t, 0, b, 0, N);
                }
            }
        }
        suc+="La complejidad lineal es: ";
        suc+=Integer.toString(l);
        suc+= ", y el polinomio de conexion es: ";
        //Eliminar ceros a la derecha
        for (cont = c.length-1; c[cont] != 1; cont--)
             ;
            
        for (int i = 0; i <= cont; i++){
             if (c[i]==1) 
                 s+= '1';
             else 
                 s+= '0';
        }
        suc+=s;
        
        return suc;
    }