Content deleted Content added
No edit summary |
No edit summary |
||
Line 18:
At the end of the algorithm, <math>L</math> is the length of the minimal LFSR for the stream, and we have <math>c_Ls_a + c_{L-1}s_{a+1} + c_{L-2}s_{a+2} ... = 0</math> for all <math>a</math>.
==Code Sample==
<source lang="csharp">
byte[] b, c, t, s;
int N, L, m;
int position = 0;
public BerlekampRegistryTester(int sequenceLenght)
{
b = new byte[sequenceLenght];
c = new byte[sequenceLenght];
t = new byte[sequenceLenght];
s = new byte[sequenceLenght];
for (int i = 0; i < sequenceLenght; i++)
{
b[i] = c[i] = t[i] = 0;
}
b[0] = c[0] = 1;
N = L = 0;
m = -1;
}
private void runTest()
{
int d;
while (N < s.Length)
{
//STEP 1
d = 0;
for (int i = 0; i <= L; i++)
{
d += s[N-i] * c[i];
}
d = d % 2;
//STEP 2
if (d == 0)
{
N++;
continue;
}
//STEP 3
else
{
//3.1
t = (byte[])c.Clone();
//3.2
for (int i = 0; i <= s.Length + m - 1 - N; i++)
{
c[N - m + i] = (byte)(c[N - m + i] ^ b[i]);
}
//3.3
if (L <= (N / 2))
{
L = N + 1 - L;
m = N;
b = (byte[])t.Clone();
}
else
{
//leave m,l,b alone
}
N++;
}
}
}
</source>
==See also==
|