Systemsicherheit/Assignment 5 - Software Security - Teil 1/crackme/crackme.c

44 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define the length of the serial number
#define SERIAL_LENGTH 5
int verify_key(char *serial) {
// Allocate a buffer to store the derived key (5 capital letters + null byte)
char derived[SERIAL_LENGTH + 1] = {0};
// Derive the key from the serial by iterating over the serial
// and subtracting 2 times the current index from each character
for(int i = 0; i < SERIAL_LENGTH; i++) {
derived[i] = serial[i] - 2 * i;
}
// Compare the derived key with the expected key "MMNNQ"
if(strcmp(derived, "MMNNQ") == 0)
return 1; // Return 1 if the keys match
return 0; // Return 0 if the keys do not match
}
int main(int argc, char **argv) {
// Buffer to store the user input (5 capital letters + null byte)
char serial[SERIAL_LENGTH + 1] = {0};
// Read the serial number from the user and store it in the serial buffer
printf("Enter serial (5 capital letters):\n");
scanf("%5s", serial);
// Verify the serial number
if(verify_key(serial)) {
// Print this message if the serial is correct
printf("Key is valid! Whoop whoop :)\n");
} else {
// Print this message if the serial is not correct
printf("Key is not valid :(\n");
}
// End the program without errors
return 0;
}