Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://en.wikipedia.org/wiki/Berlekamp%E2%80%93Massey_algorithm)
- #include <stdio.h>
- int main(void) {
- int s[]={1,1,0,0,0,0,1,0,1,0,0,1,1}; // the bits of the stream
- #define n (sizeof(s)/sizeof(*s)) // how many there are
- int b[n], c[n], t[n], x, j, N=0, L=0, m=-1;
- for(j=n; --j>0;)
- b[j]=c[j]=0;
- b[0]=c[0]=1;
- for(; N<n; ++N){
- x = s[N];
- for(j=L; j>0; --j)
- x ^= c[j]&s[N-j];
- if (x!=0){
- for(j=n; --j>=0;)
- t[j]=c[j];
- for(j=n-N+m; --j>=0;)
- c[N-m+j] ^= b[j];
- if(L+L<=N){
- L=N+1-L;
- m=N;
- for(j=n; --j>0;)
- b[j]=t[j];
- }
- }
- }
- printf("s =");
- for(j=0; j<n; j++)
- printf(" %d",s[j]);
- printf("\nc =");
- for(j=0; j<n; j++)
- printf(" %d",c[j]);
- printf("\nL = %d\n",L);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement