Skip to content

Instantly share code, notes, and snippets.

@jamesbcook
Created June 25, 2014 03:25
Show Gist options
  • Save jamesbcook/94b17f4e22e76bd50a4a to your computer and use it in GitHub Desktop.
Save jamesbcook/94b17f4e22e76bd50a4a to your computer and use it in GitHub Desktop.
package main
import (
//"bufio"
"bytes"
"crypto/md5"
"fmt"
"io"
"os"
"runtime"
"sync"
//"strings"
)
var lAlph = [26]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
var uAlph = [26]string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
var num = [10]string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
var lAlphnum = [36]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
var userPassword []byte
var wg = &sync.WaitGroup{}
func init() {
runtime.GOMAXPROCS(1)
}
func main() {
//reader := bufio.NewReader(os.Stdin)
//fmt.Print("Enter Password: ")
//userPass, _ := reader.ReadString('\n')
//userPass = strings.Replace(userPass, "\n", "", -1)
//userPassword = md5Gen(userPass)
userPassword = md5Gen2("h3llo")
possion := 5
for x := 1; x <= possion; x++ {
recurse(x, 0, "")
}
wg.Wait()
}
func recurse(width, position int, baseString string) {
for i := 0; i < len(lAlphnum); i++ {
if position < width-1 {
recurse(width, position+1, baseString+lAlphnum[i])
}
//hashed := md5Gen(baseString + lAlphnum[i])
//checkPassword(baseString + lAlphnum[i])
//checkPassword(hashed, baseString+lAlphnum[i])
wg.Add(1)
go md5Gen(baseString + lAlphnum[i])
}
}
func md5Gen(password string) {
h := md5.New()
io.WriteString(h, password)
checkPassword(h.Sum(nil), password)
}
func checkPassword(hashed []byte, password string) {
switch bytes.Compare(hashed, userPassword) {
case 0:
fmt.Println("match")
fmt.Println("Password is:", password)
os.Exit(1)
}
wg.Done()
}
func md5Gen2(password string) []byte {
h := md5.New()
io.WriteString(h, password)
return h.Sum(nil)
}
/*
func checkPassword(hashed []byte, password string) {
switch bytes.Compare(hashed, userPassword) {
case 0:
fmt.Println("match")
fmt.Println("Password is:", password)
os.Exit(1)
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment