Beispiel #1
0
 def part_decoder(self, bits, strong=False):
     bad_parity_sum = 0
     parity = 1
     while parity <= len(bits):
         summa = 0
         for i in range(len(bits)):
             if i+1 & parity and bits[i] == "1":
                 summa += 1
         if summa % 2:
             bad_parity_sum += parity
         parity *= 2
     if bad_parity_sum:
         if bad_parity_sum > self.n:
             raise base.UndecodeableError("bad_parity_sum={0} is greater then the code length={1}".format(bad_parity_sum, self.n))
         else:
             bits = base.change_bits(bits, bad_parity_sum)
     return delete_parity_bits(bits)
Beispiel #2
0
 def test_results(self):
     for args, result in self.known_pairs:
         self.assertEqual(base.change_bits(*args), result)