Skip to main content

poly_rem

Function poly_rem 

Source
pub fn poly_rem(msg: &[u8], generator: &[u8]) -> Vec<u8> ⓘ
Expand description

The remainder $r(x) = m(x), x^{r} \bmod g(x)$ of the message msg by the generator generator of degree $r$: the $r$ parity bits of a systematic cyclic code or a CRC.

The message is in transmission order (its first bit the coefficient of the highest degree), the generator lowest degree first with $g_{r} = 1$; the remainder is returned highest degree first. A shift register of $r$ bits on 64-bit words, any degree (the CRCs of 5G NR, the BCH codes of DVB-S2 of degree 192).

§Examples

use comnum_math::gf2::poly_rem;
// the (7, 4) Hamming code of g(x) = 1 + x + x³: x³ · x³ = x⁶ ≡ x² + 1
assert_eq!(poly_rem(&[1, 0, 0, 0], &[1, 1, 0, 1]), [1, 0, 1]);
assert!(poly_rem(&[1, 0, 1], &[1]).is_empty());