htb-perfection-pass/main.go

78 lines
1.7 KiB
Go
Raw Normal View History

2024-03-19 10:18:33 +01:00
package main
import (
"fmt"
"log"
"os"
"strconv"
//"time"
2024-03-19 10:18:33 +01:00
)
// {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)
2024-03-19 11:34:09 +01:00
//var writerIsFinished bool
// go func() {
// loading := "Loading"
// for {
// for i := 0; i <= 3; i++ {
// fmt.Printf("\r")
// fmt.Printf("\r%v", loading)
// loading = loading + "."
// time.Sleep(time.Second)
// if writerIsFinished == true {
// fmt.Printf("\rFinished!\n")
// os.Exit(2)
// }
// }
// loading = "Loading"
// }
// }()
2024-03-19 10:18:33 +01:00
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
}
2024-03-19 11:34:09 +01:00
func writer(name string, low int, high int) (finished bool) {
2024-03-19 10:18:33 +01:00
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)
nameToWrite := fmt.Sprintf("%v_%v_", name, reverseName)
//fmt.Println(name, reverseName, nameToWrite)
2024-03-19 11:34:09 +01:00
highFloat := float64(high)
2024-03-19 10:18:33 +01:00
for i := low; i <= high; i++ {
2024-03-19 11:34:09 +01:00
lowfloat := float64(i)
//fmt.Printf("Writing \"%v%v\" to passwords.txt...\n", nameToWrite, i)
fmt.Printf("\r%.2f%% / 100%%", (lowfloat/highFloat)*100)
file.WriteString(nameToWrite + fmt.Sprintln(i))
2024-03-19 10:18:33 +01:00
}
2024-03-19 11:34:09 +01:00
fmt.Println()
finished = true
return true
2024-03-19 10:18:33 +01:00
}