Hello ! ( i’m french )
I’m trying to create a bruteforce password software. This is a very good exercise
How i can clear the memory or limit the memory usage ?
package main
import (
"fmt"
"math"
"math/rand"
"crypto/sha1"
"bytes"
"io"
"runtime"
"time"
)
// characters used for conversion
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// converts number to base62
func Encode(number int) string {
if number == 0 {
return string(alphabet[0])
}
chars := make([]byte, 0)
length := len(alphabet)
for number > 0 {
result := number / length
remainder := number % length
chars = append(chars, alphabet[remainder])
number = result
}
for i, j := 0, len(chars) - 1; i < j; i, j = i + 1, j - 1 {
chars[i], chars[j] = chars[j], chars[i]
}
return string(chars)
}
// converts base62 token to int
func Decode(token string) int {
number := 0
idx := 0.0
chars := []byte(alphabet)
charsLength := float64(len(chars))
tokenLength := float64(len(token))
for _, c := range []byte(token) {
power := tokenLength - (idx + 1)
index := bytes.IndexByte(chars, c)
number += index * int(math.Pow(charsLength, power))
idx++
}
return number
}
func TestPassword(token int) string {
password := Encode(token)
bases++
return password
}
var bases = 0;
var password_cible = "a05bd890c4868ea1807f8564055d1fba77c6ba81"
func hash(){
password := TestPassword(bases)
h := sha1.New()
io.WriteString(h, password)
password_hash := fmt.Sprintf("%x", h.Sum(nil))
//fmt.Println(password_hash , " | ", bases, " | ", password)
if password_hash != password_cible {
hash()
} else {
fmt.Println(password_hash, " PASSWORD CRACKED ", password)
}
}
func main(){
hash()
}
The memory ram increases more and more and crashes windows
Thx !!!