Design and implementation of attack-resilient cyber-physical systems