Advertisement
Guest User

Untitled

a guest
May 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. // https://en.wikipedia.org/wiki/Berlekamp%E2%80%93Massey_algorithm)
  2. #include <stdio.h>
  3. int main(void) {
  4. int s[]={1,1,0,0,0,0,1,0,1,0,0,1,1}; // the bits of the stream
  5. #define n (sizeof(s)/sizeof(*s)) // how many there are
  6. int b[n], c[n], t[n], x, j, N=0, L=0, m=-1;
  7. for(j=n; --j>0;)
  8. b[j]=c[j]=0;
  9. b[0]=c[0]=1;
  10. for(; N<n; ++N){
  11. x = s[N];
  12. for(j=L; j>0; --j)
  13. x ^= c[j]&s[N-j];
  14. if (x!=0){
  15. for(j=n; --j>=0;)
  16. t[j]=c[j];
  17. for(j=n-N+m; --j>=0;)
  18. c[N-m+j] ^= b[j];
  19. if(L+L<=N){
  20. L=N+1-L;
  21. m=N;
  22. for(j=n; --j>0;)
  23. b[j]=t[j];
  24. }
  25. }
  26. }
  27. printf("s =");
  28. for(j=0; j<n; j++)
  29. printf(" %d",s[j]);
  30. printf("\nc =");
  31. for(j=0; j<n; j++)
  32. printf(" %d",c[j]);
  33. printf("\nL = %d\n",L);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement