Skip to content

Commit

Permalink
Merge pull request #3 from BinopOY/fix--test-all-codes-to-all-exams
Browse files Browse the repository at this point in the history
fix(executable): test all the codes against all the exams
  • Loading branch information
Adventune authored Jan 11, 2024
2 parents 6d91af5 + 0a5ac4e commit b34b2de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/executable/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 9 additions & 30 deletions src/executable/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -151,14 +135,9 @@ func main() {
}
successfulExams = append(successfulExams, examName)
// Break for loop
fileDecrypted = true
break
}
}
if !fileDecrypted {
fmt.Println("unused_code:", code)
}

}

remainingFiles := fileops.GetMexFiles()
Expand Down

0 comments on commit b34b2de

Please sign in to comment.