[Assignment-5] added solution task 2 (crackme)

This commit is contained in:
Sascha Tommasone 2024-06-08 18:07:23 +02:00
parent 1474477dc2
commit 8afa5409e6
Signed by: saschato
GPG key ID: 751068A86FCAA217
3 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,4 @@
.phony: all
all: crackme
crackme:
gcc -o crackme -m32 -O0 -fno-pie -fno-stack-protector crackme.c

View file

@ -0,0 +1,44 @@
#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;
}

View file

@ -0,0 +1 @@
MORTY