#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int decrypt(char key)
{
	unsigned int len;
	char str[28];

	// Stack canary protection (or SSP)
	// *(_DWORD *)((char *)&str[4] + 1) = __readgsdword(0x14u);
	//
	strcpy((char *)str, "Q}|u`sfg~sf{}|a3");
	len = strlen((const char *)str);
	for (int i = 0; i < len; ++i)
		str[i] ^= key;
	// Key needs to equal 12
	if (!strcmp((const char *)str, "Congratulations!"))
		return system("/bin/sh");
	else
		return puts("\nInvalid Password");
}

int test(int a1, int a2)
{
	int result;
	char key;

	switch (a2 - a1) {
	case 1:
	case 2:
	case 3:
	case 4:
	case 5:
	case 6:
	case 7:
	case 8:
	case 9:
	case 16:
	case 17:
	case 18:
	case 19:
	case 20:
	case 21:
		result = decrypt(a2 - a1);
		break;
	default:
		key = rand();
		result = decrypt(key);
		break;
	}
	return result;
}

int main(void)
{
	int input;

	srand(time(NULL));
	puts("***********************************");
	puts("*\t\tlevel03\t\t**");
	puts("***********************************");
	printf("Password:");
	scanf("%d", &input);
	test(input, 322424845);

	return 0;
}
