示例#1
0
 def __encode(self):
   """
   Encodes the raw message with the supplied generators.
   """
   tmp_msg = ""
   for i in range(len(self.mesg)-self.k+1):
     for g in self.gen_polys:
       last = string_utils.str_dot(self.mesg[i:i+self.k], g[::-1]) # reverse g
       tmp_msg+=last
   return tmp_msg
示例#2
0
 def gen_lookup(self):
   """
   Pre-computes the trellis transition information
   """
   lookup_table = {}
   for i in range(2**(self.k-1)): # for each node in the column
     key = string_utils.int_to_bin_string(i, self.k)
     transition_info = []
     for i in ["0", "1"]: #for both possible message bits (1 or 0)
       next_key = i + key[:-1]
       parity_arr = [string_utils.str_dot(poly, i+key) for poly in self.gen_polys]
       parity_bits = "".join(parity_arr)
       transition_info.append((i, parity_bits, next_key)) #determine the parity bits and next node
     lookup_table[key] = transition_info
   return lookup_table