Function crypto::hamming::encode

source ·
pub fn encode(d: [bool; 4]) -> [bool; 7]
Expand description

This function encodes a (7, 4) Hamming Code, which uses 3 parity bits for the four bits of data. These each XOR 3 of the data bits so they can tolerate one of the data bits being flipped:

  1. d[0] ^ d[1] ^ d[3]
  2. d[0] ^ d[2] ^ d[3]
  3. d[1] ^ d[2] ^ d[3]

The function then intersperses the parity bits with the data bits and returns the encoded array, like so: [p1, p2, d[0], p3, d[1], d[2], d[3]] The order of the bits doesn’t matter, as long as the decoding process xors the right bits to recover the parity bits. This arrangement is chosen so the positions of the data is easier to recover, with only 2 shifts on $p_1$ and $p_2$.