Skip to content

Instantly share code, notes, and snippets.

@pkulak
Created May 19, 2014 19:09
Show Gist options
  • Save pkulak/f1aa70e290ed29da9df0 to your computer and use it in GitHub Desktop.
Save pkulak/f1aa70e290ed29da9df0 to your computer and use it in GitHub Desktop.
A super-convoluted way to find my email address.
package main
import (
"crypto/md5"
"fmt"
"io"
"runtime"
)
var chars = "abcdefghijklmnopqrstuvwxyz"
var size = 0
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
size = len(chars)
allForLength(6)
}
func allForLength(l int) {
ints := make([]int, l, l)
work := make(chan string)
done := make(chan bool)
for i := 0; i < runtime.NumCPU(); i++ {
go func() {
for true {
s, ok := <-work
if ok {
if makeHash(s+"@gmail.com") == "62435c5225aaefe8d66401a546ec48a4" {
fmt.Println("FOUND IT!!! " + s)
}
} else {
done <- true
return
}
}
}()
}
check := func() {
s := ""
p := true
for i := 0; i < l; i++ {
// This may slow it down a tad, but otherwise we're lost!
if i > 0 && ints[i] != 0 {
p = false
}
s += chars[ints[i]:ints[i]+1]
}
if p {
fmt.Println(s)
}
work <- s
}
check()
for increment(ints) {
check()
}
close(work)
for i := 0; i < runtime.NumCPU(); i++ {
<-done
}
}
func increment(ints []int) bool {
for i := len(ints) - 1; i >= 0; i-- {
if ints[i] < size-1 {
ints[i]++
return true
} else {
ints[i] = 0
}
}
return false
}
func makeHash(s string) string {
hasher := md5.New()
io.WriteString(hasher, s)
return fmt.Sprintf("%x", hasher.Sum(nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment