#include #include #include #include // a seemingly innocent password-checker // (assuming ans is hidden and ans has len 8) bool check(char *guess, char *ans) { int i=0; for(; i < 8; i++) { sleep(1); // I'm just emphasizing the problem to make it easier to measure if(guess[i] != ans[i]) { return false; } } return true; } // if can only check answers, exhaustive search // required. // but if can see timing, linear time // better: bool check2(char *guess, char *ans) { int i=0; bool result = true; for(; i < 8; i++) { sleep(1); // Using same delay as above if(guess[i] != ans[i]) { result = false; } } return result; } int main(int argc, char** argv) { char ans[] = "12345678"; if ( argc > 1 && (strlen(argv[1])==8)) { printf("Password check: %d\n", check(argv[1],ans)); } return 0; }