invert_rules function

invert_rules inverts a set of encoding rules.