Skip to main content

decode_regular_errors

Function decode_regular_errors 

Source
pub fn decode_regular_errors(
    residue_xor_const: u128,
    data_with_checksum_len: usize,
) -> Option<(Vec<usize>, Vec<u8>)>
Expand description

Decode a regular-code BCH error pattern. Inputs:

  • residue_xor_const: the value polymod(hrp_expand(hrp) || data_with_checksum) ⊕ MK_REGULAR_CONST. By the BCH syndrome property, this is congruent to the error polynomial E(x) modulo g_regular(x).
  • data_with_checksum_len: the total symbol count of data_with_checksum (in the 0..=93 range for the regular code).

Returns Some((positions, magnitudes)) if the algorithm finds a consistent error pattern of weight ≤ 4. Each positions[k] is an index into data_with_checksum (post-HRP-prefix); each magnitudes[k] is a GF(32) symbol that must be XORed into data_with_checksum[positions[k]] to repair the codeword. Returns None if the pattern is uncorrectable.