Created
April 1, 2013 22:52
-
-
Save zwass/5288454 to your computer and use it in GitHub Desktop.
For cracking the hash in http://xkcd.com/1193/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"crypto/skein" //https://github.com/wernerd/Skein3Fish | |
"encoding/hex" | |
"os" | |
"bufio" | |
"io" | |
"strings" | |
) | |
const goal string = "5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fdf9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6" | |
func hash (in string) []byte { | |
var empty []byte | |
skein, _ := skein.NewMac(1024, 1024, empty) | |
skein.Update([]byte(in)) | |
res := skein.DoFinal() | |
return res | |
} | |
func compBytes (a, b []byte) int { | |
res := 0 | |
for i := 0; i < len(a); i++ { | |
res += compByte(a[i], b[i]) | |
} | |
return res | |
} | |
func compByte (a, b byte) int { | |
res := 0 | |
for i := uint32(0); i < 8; i++ { | |
if ((a >> i) & 1) != ((b >> i) & 1) { | |
res += 1; | |
} | |
} | |
return res | |
} | |
func main() { | |
best := 1000 | |
goalbytes, _ := hex.DecodeString(goal) | |
reader := bufio.NewReader(os.Stdin) | |
for line, err := reader.ReadString('\n'); err != io.EOF ; line, err = reader.ReadString('\n'){ | |
word := strings.Split(line, "\n")[0] | |
res := compBytes(hash(word), goalbytes) | |
if res < best { | |
fmt.Printf("%d '%s'\n", res, word) | |
best = res | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment