From c2b4c2493d103de34f5aba8bd2278afdaa22fc34 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 19 Mar 2024 10:18:33 +0100 Subject: [PATCH] Adding initial files --- .gitignore | 1 + go.mod | 3 +++ main.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/.gitignore b/.gitignore index adf8f72..12c2348 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.dll *.so *.dylib +passwords.txt # Test binary, built with `go test -c` *.test diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..39f1493 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module htb-perfection-pass + +go 1.22.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..4c3082b --- /dev/null +++ b/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "log" + "os" + "strconv" +) + +// {firstname}_{firstname backwards}_{randomly generated integer between 1 and 1,000,000,000} + +func main() { + if len(os.Args) != 4 { + fmt.Println("Usage: ./perfection-crack susan 1 1000000000") + os.Exit(0) + } + //fmt.Println(os.Args[1], os.Args[2], os.Args[3]) + name := os.Args[1] + minNum := os.Args[2] + maxNum := os.Args[3] + + minNumInt, _ := strconv.Atoi(minNum) + maxNumInt, _ := strconv.Atoi(maxNum) + + writer(name, minNumInt, maxNumInt) + +} + +func reverseString(str string) (revStr string) { + strByte := []rune(str) + for i := len(strByte) - 1; i >= 0; i-- { + revStr += string(strByte[i]) + } + return revStr +} + +func writer(name string, low int, high int) { + file, err := os.OpenFile("./passwords.txt", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0640) + if err != nil { + log.Fatalf("Error occurred: %v\n", err) + } + defer file.Close() + + reverseName := reverseString(name) + fmt.Println(name, reverseName) + os.Exit(2) + + for i := low; i < high; i++ { + //nameToWrite := name + file.WriteString(name) + + } +}