Eliminating Input Based Attacks by Deriving Encoders and Decoders from CFGs