From f9050ea3f0377d6812ff16fb8e8e553d3c97c3bd Mon Sep 17 00:00:00 2001 From: Adventune Date: Thu, 11 Jan 2024 14:07:39 +0200 Subject: [PATCH 1/2] fix: test all the codes against all the files --- src/executable/build.sh | 4 +-- src/executable/main.go | 78 +++++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/src/executable/build.sh b/src/executable/build.sh index af69197..b07b204 100644 --- a/src/executable/build.sh +++ b/src/executable/build.sh @@ -2,5 +2,5 @@ # Build the project echo "Building the project..." -GOOS=linux GOARCH=amd64 go build -o ./build/mexer_amd64 -GOOS=windows GOARCH=amd64 go build -o ./build/mexer_amd64.exe +GOOS=linux GOARCH=amd64 go build -o ./build/mexer_amd64_linux +GOOS=windows GOARCH=amd64 go build -o ./build/mexer_amd64_windows.exe diff --git a/src/executable/main.go b/src/executable/main.go index 5563d79..aceb0a5 100644 --- a/src/executable/main.go +++ b/src/executable/main.go @@ -79,17 +79,6 @@ func main() { log.Fatal("No files to process") } - if len(files) > len(codes) { - if len(codes) == 1 { - // If only one code is given, then it is a single code for all files - for i := 0; i < len(files)-1; i++ { - codes = append(codes, codes[0]) - } - } else { - log.Fatal("Number of codes is less than number of files") - } - } - // Result arrays var failedExams []failedExam var successfulExams []string @@ -123,24 +112,19 @@ func main() { } } - // Decrypt - for _, code := range codes { - files = fileops.GetMexFiles() + files = fileops.GetMexFiles() + for _, file := range files { if len(files) == 0 { // All files are processed break } - // Remove all whitespaces from code - noWhitespaceCode := strings.ReplaceAll(code, " ", "") - - key, iv, err := crypto.DeriveAES256KeyAndIV(noWhitespaceCode) - if err != nil { - log.Fatal(err) - } - - fileDecrypted := false - for _, file := range files { - // Decrypt file + for _, code := range codes { + // Remove all whitespaces from code + noWhitespaceCode := strings.ReplaceAll(code, " ", "") + key, iv, err := crypto.DeriveAES256KeyAndIV(noWhitespaceCode) + if err != nil { + log.Fatal(err) + } successful, examName := crypto.DecryptFile(file, key, iv) if successful { // File decrypted successfully @@ -151,15 +135,49 @@ func main() { } successfulExams = append(successfulExams, examName) // Break for loop - fileDecrypted = true break } } - if !fileDecrypted { - fmt.Println("unused_code:", code) - } - } + // Decrypt + /* + for _, code := range codes { + files = fileops.GetMexFiles() + if len(files) == 0 { + // All files are processed + break + } + // Remove all whitespaces from code + noWhitespaceCode := strings.ReplaceAll(code, " ", "") + + key, iv, err := crypto.DeriveAES256KeyAndIV(noWhitespaceCode) + if err != nil { + log.Fatal(err) + } + + fileDecrypted := false + for _, file := range files { + // Decrypt file + successful, examName := crypto.DecryptFile(file, key, iv) + if successful { + // File decrypted successfully + // Remove file from unzipped dir + err = os.Remove(file) + if err != nil { + log.Fatal(err) + } + successfulExams = append(successfulExams, examName) + // Break for loop + fileDecrypted = true + break + } + } + if !fileDecrypted { + fmt.Println("unused_code:", code) + } + + } + */ remainingFiles := fileops.GetMexFiles() for _, file := range remainingFiles { From 0a5ac4e3d4a8ca37f188384b76c6477d5adef2cf Mon Sep 17 00:00:00 2001 From: Adventune Date: Thu, 11 Jan 2024 14:08:46 +0200 Subject: [PATCH 2/2] fix: remove unused code --- src/executable/main.go | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/src/executable/main.go b/src/executable/main.go index aceb0a5..ba50f2d 100644 --- a/src/executable/main.go +++ b/src/executable/main.go @@ -139,45 +139,6 @@ func main() { } } } - // Decrypt - /* - for _, code := range codes { - files = fileops.GetMexFiles() - if len(files) == 0 { - // All files are processed - break - } - // Remove all whitespaces from code - noWhitespaceCode := strings.ReplaceAll(code, " ", "") - - key, iv, err := crypto.DeriveAES256KeyAndIV(noWhitespaceCode) - if err != nil { - log.Fatal(err) - } - - fileDecrypted := false - for _, file := range files { - // Decrypt file - successful, examName := crypto.DecryptFile(file, key, iv) - if successful { - // File decrypted successfully - // Remove file from unzipped dir - err = os.Remove(file) - if err != nil { - log.Fatal(err) - } - successfulExams = append(successfulExams, examName) - // Break for loop - fileDecrypted = true - break - } - } - if !fileDecrypted { - fmt.Println("unused_code:", code) - } - - } - */ remainingFiles := fileops.GetMexFiles() for _, file := range remainingFiles {