fn berlekamp_massey(s: &[u8; MAX_POLY], N: usize, gf: &GaloisField) -> [u8; MAX_POLY] {
    let mut C: [u8; MAX_POLY] = [0; MAX_POLY];
    let mut B: [u8; MAX_POLY] = [0; MAX_POLY];
    let mut L: usize = 0;
    let mut m: i32 = 1;
    let mut b: u8 = 1;

    B[0] = 1;
    C[0] = 1;

    for n in 0..N {
        let mut d: u8 = s[n];

        for i in 1..=L {
            if C[i] != 0 && (s[n - i] != 0) {
                d ^= gf.exp[((i32::from(gf.log[C[i as usize] as usize])
                    + i32::from(gf.log[s[n - i] as usize]))
                    % gf.p) as usize];
            }
        }

        let mult = gf.exp[((gf.p - i32::from(gf.log[b as usize]) + i32::from(gf.log[d as usize]))
            % gf.p) as usize];

        if d == 0 {
            m += 1;
        } else if L * 2 <= n {
            let T = C;
            poly_add(&mut C, &B, mult, m, gf);
            B = T;
            L = n + 1 - L;
            b = d;
            m = 1;
        } else {
            poly_add(&mut C, &B, mult, m, gf);
            m += 1;
        }
    }

    C
}
/// Berlekamp-Massey algorithm for finding error locator polynomials.
Berlekamp-Massey algorithm for finding error locator polynomials.
Berlekamp - Massey algorithm for finding error locator polynomials .
fn berlekamp_massey(s: &[u8; MAX_POLY], N: usize, gf: &GaloisField) -> [u8; MAX_POLY] {
    let mut C: [u8; MAX_POLY] = [0; MAX_POLY];
    let mut B: [u8; MAX_POLY] = [0; MAX_POLY];
    let mut L: usize = 0;
    let mut m: i32 = 1;
    let mut b: u8 = 1;
    B[0] = 1;
    C[0] = 1;
    for n in 0..N {
        let mut d: u8 = s[n];
        for i in 1..=L {
            if C[i] != 0 && (s[n - i] != 0) {
                d ^= gf.exp[((i32::from(gf.log[C[i as usize] as usize])
                    + i32::from(gf.log[s[n - i] as usize]))
                    % gf.p) as usize];
            }
        }
        let mult = gf.exp[((gf.p - i32::from(gf.log[b as usize]) + i32::from(gf.log[d as usize]))
            % gf.p) as usize];
        if d == 0 {
            m += 1;
        } else if L * 2 <= n {
            let T = C;
            poly_add(&mut C, &B, mult, m, gf);
            B = T;
            L = n + 1 - L;
            b = d;
            m = 1;
        } else {
            poly_add(&mut C, &B, mult, m, gf);
            m += 1;
        }
    }
    C
}
fn berlekamp_massey ( s : & [ u8 ; MAX_POLY ] , N : usize , gf : & GaloisField ) -> [ u8 ; MAX_POLY ] { let mut C : [ u8 ; MAX_POLY ] = [ 0 ; MAX_POLY ] ; let mut B : [ u8 ; MAX_POLY ] = [ 0 ; MAX_POLY ] ; let mut L : usize = 0 ; let mut m : i32 = 1 ; let mut b : u8 = 1 ; B [ 0 ] = 1 ; C [ 0 ] = 1 ; for n in 0 .. N { let mut d : u8 = s [ n ] ; for i in 1 ..= L { if C [ i ] != 0 && ( s [ n - i ] != 0 ) { d ^= gf . exp [ ( ( i32 :: from ( gf . log [ C [ i as usize ] as usize ] ) + i32 :: from ( gf . log [ s [ n - i ] as usize ] ) ) % gf . p ) as usize ] ; } } let mult = gf . exp [ ( ( gf . p - i32 :: from ( gf . log [ b as usize ] ) + i32 :: from ( gf . log [ d as usize ] ) ) % gf . p ) as usize ] ; if d == 0 { m += 1 ; } else if L * 2 <= n { let T = C ; poly_add ( & mut C , & B , mult , m , gf ) ; B = T ; L = n + 1 - L ; b = d ; m = 1 ; } else { poly_add ( & mut C , & B , mult , m , gf ) ; m += 1 ; } } C }
Berlekamp-Massey algorithm for finding error locator polynomials.
Berlekamp - Massey algorithm for finding error locator polynomials .
s
&[u8; MAX_POLY]
N
usize
gf
&GaloisField
s
&[u8; MAX_POLY]
N
usize
gf
&GaloisField