/* Save this as 'secret.c' and type 'cc secret.c -o secret' to compile. */ #include #include #include #include main(argc, argv) int argc; char **argv; { struct sgttyb basic; short flags; char str[32]; int i; /* Ignore all interrupts that may try to mess up this program like ^C, ^Z */ for (i = 1; i < 33; signal(i++, SIG_IGN)); /* Shut off echo and receive key strokes as they are hit from the terminal */ ioctl(fileno(stdin), TIOCGETP, &basic); flags = basic.sg_flags; basic.sg_flags |= CBREAK; basic.sg_flags &= ~ECHO; ioctl(fileno(stdin), TIOCSETP, &basic); do { /* Prompt for the input */ fprintf(stdout, "Enter Secret Word> "), fflush(stdout); /* Get the input until a return or a lot of keys are hit */ for (i = 0; (i < 31) && ((str[i] = getchar()) != '\n'); i++); /* Terminate the string */ str[i] = '\0'; /* Acknowledge that you have accepted the return by echoing it */ fprintf(stdout, "\n"); /* Repeat until the word has been entered */ } while (strcmp(crypt(str, "hi"), "higSfxQjrCp7Y")); /* Restore the terminal back to the original settings */ basic.sg_flags = flags; ioctl(fileno(stdin), TIOCSETP, &basic); /* Do something with the secret string here, I just print it out... You could have fun with it */ fprintf(stdout, "->%s\n", str); fflush(stdout); }