(* Encoding is done by iteratively applying find_code *)
Fixpoint encode (c : code) (m : list A) {struct m} : list bool :=
  match m with
  | nil => nil
  | a :: b => find_code a c ++ encode c b
  end.

Theorem encode_permutation_val : forall m1 m2 c, permutation m1 m2 -> permutation (encode c m1) (encode c m2).