From 040c0c153eb6e16a5c42ccc8f7473584d5a70306 Mon Sep 17 00:00:00 2001 From: Dan Goldsmith Date: Mon, 25 Sep 2023 08:13:20 +0100 Subject: [PATCH] rename Folders to be more sensible --- {Asm => Week2_ASM}/Password | Bin {Asm => Week2_ASM}/Password2 | Bin {Asm => Week2_ASM}/Password3 | Bin {Week3 => Week3_Compiler}/1_Simpl | Bin {Week3 => Week3_Compiler}/2_Function | Bin {Week3 => Week3_Compiler}/3_Mangle | Bin {Week3 => Week3_Compiler}/4_Operation | Bin {Week3 => Week3_Compiler}/5_Operation | Bin Week3_Compiler/sources/2_Function.c | 43 +++++++++++++++ Week3_Compiler/sources/3_Mangle.c | 32 +++++++++++ Week3_Compiler/sources/4_Operation.c | 41 ++++++++++++++ Week3_Compiler/sources/4_Process.c | 68 ++++++++++++++++++++++++ Week3_Compiler/sources/5_Process.c | 68 ++++++++++++++++++++++++ Week3_Compiler/sources/SimplePassword.c | 21 ++++++++ 14 files changed, 273 insertions(+) rename {Asm => Week2_ASM}/Password (100%) rename {Asm => Week2_ASM}/Password2 (100%) rename {Asm => Week2_ASM}/Password3 (100%) rename {Week3 => Week3_Compiler}/1_Simpl (100%) rename {Week3 => Week3_Compiler}/2_Function (100%) rename {Week3 => Week3_Compiler}/3_Mangle (100%) rename {Week3 => Week3_Compiler}/4_Operation (100%) rename {Week3 => Week3_Compiler}/5_Operation (100%) create mode 100644 Week3_Compiler/sources/2_Function.c create mode 100644 Week3_Compiler/sources/3_Mangle.c create mode 100644 Week3_Compiler/sources/4_Operation.c create mode 100644 Week3_Compiler/sources/4_Process.c create mode 100644 Week3_Compiler/sources/5_Process.c create mode 100644 Week3_Compiler/sources/SimplePassword.c diff --git a/Asm/Password b/Week2_ASM/Password similarity index 100% rename from Asm/Password rename to Week2_ASM/Password diff --git a/Asm/Password2 b/Week2_ASM/Password2 similarity index 100% rename from Asm/Password2 rename to Week2_ASM/Password2 diff --git a/Asm/Password3 b/Week2_ASM/Password3 similarity index 100% rename from Asm/Password3 rename to Week2_ASM/Password3 diff --git a/Week3/1_Simpl b/Week3_Compiler/1_Simpl similarity index 100% rename from Week3/1_Simpl rename to Week3_Compiler/1_Simpl diff --git a/Week3/2_Function b/Week3_Compiler/2_Function similarity index 100% rename from Week3/2_Function rename to Week3_Compiler/2_Function diff --git a/Week3/3_Mangle b/Week3_Compiler/3_Mangle similarity index 100% rename from Week3/3_Mangle rename to Week3_Compiler/3_Mangle diff --git a/Week3/4_Operation b/Week3_Compiler/4_Operation similarity index 100% rename from Week3/4_Operation rename to Week3_Compiler/4_Operation diff --git a/Week3/5_Operation b/Week3_Compiler/5_Operation similarity index 100% rename from Week3/5_Operation rename to Week3_Compiler/5_Operation diff --git a/Week3_Compiler/sources/2_Function.c b/Week3_Compiler/sources/2_Function.c new file mode 100644 index 0000000..6bce781 --- /dev/null +++ b/Week3_Compiler/sources/2_Function.c @@ -0,0 +1,43 @@ +#include +#include + +#define BUFFSIZE 30 + + +int checkPassword(char *buffer){ + + int match; + + if (strcmp(buffer, "Selector") == 0){ + return 1; + } + + if (strcmp(buffer, "Specials") == 0){ + return 2; + } + + if (strcmp(buffer, "Beat") == 0){ + return 3; + } + + return -1; +} + + +void main(void){ + char buffer[BUFFSIZE]; + + printf("Enter Password> "); + fgets(buffer, BUFFSIZE, stdin); + //Remove the Newlines + buffer[strcspn(buffer, "\r\n")] = 0; + + int returnVal = checkPassword(buffer); + + if (returnVal == 2){ + printf("Win!!\n"); + } + else + printf("Lose\n"); + +} diff --git a/Week3_Compiler/sources/3_Mangle.c b/Week3_Compiler/sources/3_Mangle.c new file mode 100644 index 0000000..1f9a2ba --- /dev/null +++ b/Week3_Compiler/sources/3_Mangle.c @@ -0,0 +1,32 @@ +#include +#include + +#define BUFFSIZE 30 + + +int checkPassword(char *buffer){ + char passText[] = "ALongerString"; + + passText[7] = '\0'; + int out = strcmp(passText, buffer); + return out; +} + +void main(void){ + char buffer[BUFFSIZE]; + + printf("Enter Password> "); + fgets(buffer, BUFFSIZE, stdin); + //Remove the Newlines + buffer[strcspn(buffer, "\r\n")] = 0; + + //Get the Length + int returnVal = checkPassword(buffer); + + if (returnVal == 0){ + printf("Win!!\n"); + } + else + printf("Lose\n"); + +} diff --git a/Week3_Compiler/sources/4_Operation.c b/Week3_Compiler/sources/4_Operation.c new file mode 100644 index 0000000..15e9374 --- /dev/null +++ b/Week3_Compiler/sources/4_Operation.c @@ -0,0 +1,41 @@ +#include +#include + +#define BUFFSIZE 30 + +int checkPassword(char *buffer){ + + char *magicWord = "HelloWorld"; + + if (strlen(buffer) > 5){ + return -1; + } + + for (int x=0; x<5; x++){ + if (buffer[x] != magicWord[x]){ + return -2; + } + } + + return 0; +} + + +void main(void){ + char buffer[BUFFSIZE]; + + printf("Enter Password> "); + fgets(buffer, BUFFSIZE, stdin); + //Remove the Newlines + buffer[strcspn(buffer, "\r\n")] = 0; + + int returnVal = checkPassword(buffer); + //int returnVal = process_first(buffer); + + if (returnVal == 0){ + printf("Win!!\n"); + } + else + printf("Lose\n"); + +} diff --git a/Week3_Compiler/sources/4_Process.c b/Week3_Compiler/sources/4_Process.c new file mode 100644 index 0000000..f2bb170 --- /dev/null +++ b/Week3_Compiler/sources/4_Process.c @@ -0,0 +1,68 @@ +#include +#include + +#define BUFFSIZE 30 + + +int process_first(char *buffer){ + + int strlen = 0; + + //Work out length of string + for (strlen = 0; strlen <= BUFFSIZE; strlen++){ + if (buffer[strlen] == '\0'){ + return strlen; + } + } + return strlen; +} + +int checkPassword(char *buffer, int strlen){ + + char magicWord[] = "HelloWorld"; + + char tempbuffer[strlen]; + + int y = 0; + + for (int x = strlen - 1; x >= 0; x--){ + tempbuffer[y] = magicWord[x]; + y+=1; + } + + tempbuffer[strlen] = '\0'; + + if (strcmp(tempbuffer, buffer) == 0){ + return 0; + } + else{ + return -1; + } + + +} + + + + + +void main(void){ + char buffer[BUFFSIZE]; + + printf("Enter Password> "); + fgets(buffer, BUFFSIZE, stdin); + //Remove the Newlines + buffer[strcspn(buffer, "\r\n")] = 0; + + //Get the Length + int strlen = process_first(buffer); + int returnVal = checkPassword(buffer, strlen); + //int returnVal = process_first(buffer); + + if (returnVal == 0){ + printf("Win!!\n"); + } + else + printf("Lose\n"); + +} diff --git a/Week3_Compiler/sources/5_Process.c b/Week3_Compiler/sources/5_Process.c new file mode 100644 index 0000000..f2bb170 --- /dev/null +++ b/Week3_Compiler/sources/5_Process.c @@ -0,0 +1,68 @@ +#include +#include + +#define BUFFSIZE 30 + + +int process_first(char *buffer){ + + int strlen = 0; + + //Work out length of string + for (strlen = 0; strlen <= BUFFSIZE; strlen++){ + if (buffer[strlen] == '\0'){ + return strlen; + } + } + return strlen; +} + +int checkPassword(char *buffer, int strlen){ + + char magicWord[] = "HelloWorld"; + + char tempbuffer[strlen]; + + int y = 0; + + for (int x = strlen - 1; x >= 0; x--){ + tempbuffer[y] = magicWord[x]; + y+=1; + } + + tempbuffer[strlen] = '\0'; + + if (strcmp(tempbuffer, buffer) == 0){ + return 0; + } + else{ + return -1; + } + + +} + + + + + +void main(void){ + char buffer[BUFFSIZE]; + + printf("Enter Password> "); + fgets(buffer, BUFFSIZE, stdin); + //Remove the Newlines + buffer[strcspn(buffer, "\r\n")] = 0; + + //Get the Length + int strlen = process_first(buffer); + int returnVal = checkPassword(buffer, strlen); + //int returnVal = process_first(buffer); + + if (returnVal == 0){ + printf("Win!!\n"); + } + else + printf("Lose\n"); + +} diff --git a/Week3_Compiler/sources/SimplePassword.c b/Week3_Compiler/sources/SimplePassword.c new file mode 100644 index 0000000..e119b1f --- /dev/null +++ b/Week3_Compiler/sources/SimplePassword.c @@ -0,0 +1,21 @@ +#include +#include + +#define BUFFSIZE 30 +#define PASSWORD "SwordF1sh!" + +void main(void){ + char buffer[BUFFSIZE]; + + printf("Enter Password> "); + fgets(buffer, BUFFSIZE, stdin); + //Remove the Newlines + buffer[strcspn(buffer, "\r\n")] = 0; + + if (strcmp(buffer, PASSWORD) == 0){ + printf("Win!!\n"); + } + else + printf("Lose\n"); + +}