Skip to content

Instantly share code, notes, and snippets.

@antonva
Last active October 19, 2015 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonva/25ecd878762cc0cf3526 to your computer and use it in GitHub Desktop.
Save antonva/25ecd878762cc0cf3526 to your computer and use it in GitHub Desktop.
#include <stdio.h>
void init_input(int *input, size_t psize) {
for (size_t i = 0; i < psize; i++) {
input[i] = 99;
}
}
int check_password(int *password, size_t psize, int *input) {
for (size_t i = 0; i < psize; i++) {
if (input[i] > 9) { return -2; } //Means that the input isn't long enough.
if (password[i] != input[i]) { return -1; } // No need to check more digits.
}
return 1;
}
int main() {
size_t psize = 4;
int password[] = {1,3,3,7};
int input[4];
while(1) {
init_input(input, psize);
// This would be your keypad input. Try fucking around with it.
scanf("%i", &input[0]);
scanf("%i", &input[1]);
scanf("%i", &input[2]);
scanf("%i", &input[3]);
int val = check_password(password, psize, input);
if ( val == 1 ) { printf("A-access granted anona-senpai.\n"); }
else { printf("B-baka, you're not anona-kun!\n"); }
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment