Resilient Control for Cyber-Physical Systems Subject to Replay Attacks