Given a program P and a security policy Φ, this paper gives an approach allowing to generate another program P′ that respects the policy Φ and behaves (with respect to trace equivalence) like P except that it stops when P try to execute an action that violate the security policy. The proposed approach transform the problem of finding P′ to solving linear systems under a given algebra and for which we know how to get the solution.