Berlekamp–Massey algorithm: Difference between revisions

Content deleted Content added
 
(23 intermediate revisions by 16 users not shown)
Line 1:
{{Short description|Algorithm on linear-feedback shift registers}}
{{distinguish|Berlekamp's algorithm}}
[[File:Berlekamp–Massey algorithm.png|thumb|right|Berlekamp–Massey algorithm]]
The '''Berlekamp–Massey algorithm''' is an [[algorithm]] that will find the shortest [[linear -feedback shift register]] (LFSR) for a given binary output sequence. The algorithm will also find the [[Minimal polynomial (field theory)|minimal polynomial]] of a linearly [[Recurrence relation|recurrent sequence]] in an arbitrary [[field (mathematics)|field]]. The field requirement means that the Berlekamp–Massey algorithm requires all non-zero elements to have a multiplicative inverse.<ref>{{Harvnb|Reeds|Sloane|1985|p=2}}</ref> Reeds and Sloane offer an extension to handle a [[ring (mathematics)|ring]].<ref>{{Citation |lastlast1=Reeds |firstfirst1=J. A. |last2=Sloane |first2=N. J. A. |authorlink2author-link2=N. J. A. Sloane |journal=SIAM Journal on Computing |volume=14 |issue=3 |pages=505–513 |year=1985 |title=Shift-Register Synthesis (Modulo n) |url=http://neilsloane.com/doc/Me111.pdf |doi=10.1137/0214038 |citeseerx=10.1.1.48.4652 }}</ref>
 
[[Elwyn Berlekamp]] invented an algorithm for decoding [[BCH code|Bose–Chaudhuri–Hocquenghem (BCH) codes]].<ref>{{Citation
|last= Berlekamp
|first= Elwyn R.
|authorlinkauthor-link= Elwyn Berlekamp
|title= Nonbinary BCH decoding
|year= 1967
Line 12 ⟶ 14:
|last= Berlekamp
|first= Elwyn R.
|authorlinkauthor-link= Elwyn Berlekamp
|title=Algebraic Coding Theory
|place=Laguna Hills, CA
|origyearorig-year=1968
|year=1984
|edition= Revised
Line 22 ⟶ 24:
|first= J. L.
|last= Massey
|authorlinkauthor-link= James Massey
|title= Shift-register synthesis and BCH decoding
|journal= IEEE Transactions on Information Theory
Line 31 ⟶ 33:
|url= http://crypto.stanford.edu/~mironov/cs359/massey.pdf
|doi= 10.1109/TIT.1969.1054260
|s2cid= 9003708
}}</ref><ref>{{Citation
|lastlast1= Ben Atti
|firstfirst1= Nadia
|last2= Diaz-Toca
|first2= Gema M.
Line 44 ⟶ 47:
|url= http://hlombardi.free.fr/publis/ABMAvar.html
|doi= 10.1007/s00200-005-0190-z
|arxiv= 2211.11721
}}</ref> Massey termed the algorithm the LFSR Synthesis Algorithm (Berlekamp Iterative Algorithm),<ref>{{Harvnb|Massey|1969|p=124}}</ref> but it is now known as the Berlekamp–Massey algorithm.
|s2cid= 14944277
}}</ref> Massey termed the algorithm the LFSR Synthesis Algorithm (Berlekamp Iterative Algorithm),<ref>{{Harvnb|Massey|1969|p=124}}</ref> but it is now known as the Berlekamp–Massey algorithm.
 
==Description of algorithm==
Line 85 ⟶ 90:
:<math> d = d - (d/b)b = d - d = 0.</math>
 
The algorithm also needs to increase ''L'' (number of errors) as needed. If ''L'' equals the actual number of errors, then during the iteration process, the discrepancies will become zero before ''n'' becomes greater than or equal to 2''L''. Otherwise ''L'' is updated and the algorithm will update ''B''(''x''), ''b'', increase ''L'', and reset ''m'' = 1. The formula ''L'' = (''n'' + 1 − ''L'') limits ''L'' to the number of available syndromes used to calculate discrepancies, and also handles the case where ''L'' increases by more than 1.
 
==Code samplePseudocode ==
 
The algorithm from {{Harvtxt|Massey|1969|p=124}} for an arbitrary field:
 
<!-- Notes: notation changes from Massey:
Massey Here
Line 100 ⟶ 104:
T(D) T(x) polynomial
-->
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr">
<source lang=C>
polynomial(field ''K'') s(x) = ... <span class="cm">/* coeffs are s_js<sub>j</sub>; output sequence as N-1 degree polynomial) */</span>
<span class="cm">/* connection polynomial */</span>
polynomial(field K) C(x) = 1; <span class="cm">/* coeffs are c_jc<sub>j</sub> */</span>
polynomial(field K) B(x) = 1;
int L = 0;
int m = 1;
field K b = 1;
int n;
<span class="cm">/* steps 2. and 6. */</span>
 
<span class="k">for</span> (n = 0; n < N; n++) {
/* steps 2. and 6. */
<span class="cm">/* step 2. calculate discrepancy */</span>
for (n = 0; n < N; n++) {
field K d = s<sub>n</sub> + {{math|&sum;{{su|p=L|b=i=1}} c<sub>i</sub> s<sub>n - i</sub>}} <!--Σi=1Lci⋅sn−i;-->
/* step 2. calculate discrepancy */
field K d = s_n + \Sigma_{i=1}^L c_i * s_{n-i};
<span class="k">if</span> (d == 0) {
 
<span class="cm">/* step 3. discrepancy is zero; annihilation continues */</span>
if (d == 0) {
/* step 3.m discrepancy= ism zero+ 1; annihilation continues */
} <span class="k">else</span> <span class="k">if</span> (2 * L <= n) {
m = m + 1;
} else if (2 * L <span class="cm">/* n)step {5. */</span>
<span class="cm">/* steptemporary 5.copy of C(x) */</span>
/* temporary copypolynomial(field ofK) CT(x) */= C(x);
polynomial(field K) T(x) = C(x);
C(x) = C(x) - d b<sup>−1</sup> x<sup>m</sup> B(x);
 
C(x) = C(x)L -= dn + b^{-1} x^m- B(x)L;
L = nB(x) + 1 -= LT(x);
B(x) b = T(x)d;
b m = d1;
} <span m class="k">else</span> 1;{
<span class="cm">/* step 4. */</span>
} else {
C(x) = C(x) - d b<sup>−1</sup> x<sup>m</sup> B(x);
/* step 4. */
C(x) = C(x)m -= d b^{-1} x^m B(x)+ 1;
m = m + 1;
}
}
<span class="k">return</span> L;
</sourcediv>
 
In the case of binary GF(2) BCH code, the discrepancy d will be zero on all odd steps, so a check can be added to avoid calculating it.
==The algorithm for the binary field==
{{sxhl|2=c|1=<nowiki/>
 
/* ... */
The following is the Berlekamp–Massey algorithm specialized for the binary [[finite field]] F<sub>2</sub> (also written GF(2)). The field elements are '0' and '1'. The field operations '+' and '−' are identical and are equivalent to the 'exclusive or' operation, XOR. The multiplication operator '*' becomes the logical AND operation. The division operator reduces to the identity operation (i.e., field division is only defined for dividing by 1, and x/1 = x).
for (n = 0; n < N; n++) {
 
/* if odd step number, discrepancy == 0, no need to calculate it */
#Let <math>s_0, s_1, s_2 \cdots s_{N-1}</math> be the [[bit]]s of the stream.
if ((n&1) != 0) {
#Initialise two arrays <math>b</math> and <math>c</math> each of length <math>N</math> to be zeroes, except <math>b_0 \leftarrow 1, c_0 \leftarrow 1</math>
m = m + 1;
#[[Assignment (computer science)|assign]] <math>L \leftarrow 0, m \leftarrow -1</math>.
m = m + 1continue;
#'''For''' <math>n = 0</math> '''step''' 1 '''while''' <math>n < N </math>:
} else {}
#*Let discrepancy <math>d</math> be <math>s_n \oplus c_1s_{n-1} \oplus c_2s_{n-2} \oplus \cdots \oplus c_Ls_{n-L}</math>.<!-- These are operations in the FIELD -->
/* ... */
#*'''if''' <math>d = 0</math>, '''then''' <math>c</math> is already a polynomial which annihilates the portion of the stream from <math>n-L</math> to <math>n</math>.
}}
#*'''else''':
#** Let <math>t</math> be a copy of <math>c</math>.
#** Set <math>c_{n-m} \leftarrow c_{n-m} \oplus b_0, c_{n-m+1} \leftarrow c_{n-m+1} \oplus b_1, \dots </math> up to <math>c_{N-1} \leftarrow c_{N-1} \oplus b_{N-n+m-1}</math> (where <math>\oplus</math> is the [[Exclusive or]] operator).
#** If <math>L \le \frac{n}{2}</math>, set <math>L \leftarrow n+1-L</math>, set <math>m \leftarrow n</math>, and let <math>b \leftarrow t</math>; otherwise leave <math>L</math>, <math>m</math> and <math>b</math> alone.
 
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 \oplus c_{L-1}s_{a+1} \oplus c_{L-2}s_{a+2} \oplus \cdots = 0</math> for all <math>a</math>.<!-- this expression is in the FIELD -->
 
==See also==
* [[Reed–Solomon error correction]]
* [[Reeds–Sloane algorithm]], an extension for sequences over integers mod&nbsp;''n''
* [[Nonlinear-feedback shift register]] (NLFSR)
* [[NLFSR]], Non-Linear Feedback Shift Register
 
==References==
Line 164 ⟶ 162:
==External links==
* {{springer|title=Berlekamp-Massey algorithm|id=p/b120140}}
* [https://web.archive.org/web/20120716181541/http://planetmath.org/encyclopedia/{{PlanetMath|BerlekampMasseyAlgorithm.html |Berlekamp–Massey algorithm] at [[PlanetMath]].}}
* {{MathWorld|urlname=Berlekamp-MasseyAlgorithm|title=Berlekamp–Massey Algorithm}}
* [https://code.google.com/p/lfsr/ GF(2) implementation in Mathematica]
* {{dein iconlang|de}} [http://www.informationsuebertragung.ch/indexAlgorithmen.html Applet Berlekamp–Massey algorithm]
* [https://berlekamp-massey-algorithm.appspot.com/ Online GF(2) Berlekamp-Massey calculator]
 
Line 173 ⟶ 171:
[[Category:Error detection and correction]]
[[Category:Cryptanalytic algorithms]]
[[Category:Articles with example code]]