Created
January 23, 2014 08:50
-
-
Save gtfierro/8575167 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
| "crypto/sha1" | |
| "fmt" | |
| "io/ioutil" | |
| "log" | |
| "os" | |
| "strconv" | |
| "time" | |
| "sync" | |
| "encoding/hex" | |
| ) | |
| func gitMoney(difficulty string,in []byte, w *sync.WaitGroup) { | |
| hashes := 0 | |
| now := time.Now() | |
| start_second := now.Truncate(time.Second) | |
| i := 0 | |
| debug := true | |
| for { | |
| //text := fmt.Sprintf("tree %s \n parent %s \n author CTF user <[email protected]> %s +0000 \n committer CTF user <[email protected]> %s +0000 \n Give me a Gitcoin\n $d", "tree", "parent", "time", counter) | |
| //dumb | |
| t := strconv.Itoa(i) | |
| counter := []byte(t) | |
| h := sha1.New() | |
| body := append(in, counter...) | |
| fmt.Fprintf(h, "blob %d\x00", len(body)) | |
| h.Write(body) | |
| sum := h.Sum(nil) | |
| cs := hex.EncodeToString(sum[:]) | |
| if cs < difficulty { | |
| fmt.Printf("%s%s",in,t) | |
| fmt.Fprintln(os.Stderr, cs) | |
| break | |
| } | |
| hashes++ | |
| now := time.Now() | |
| end_second := now.Truncate(time.Second) | |
| if debug == true { | |
| if end_second.After(start_second) { | |
| fmt.Fprintln(os.Stderr, "hashes per second:", hashes) | |
| start_second = end_second | |
| hashes = 0 | |
| } | |
| } | |
| i++ | |
| } | |
| w.Done() | |
| } | |
| func main() { | |
| in, err := ioutil.ReadAll(os.Stdin) | |
| if err != nil { | |
| log.Println(err, string(in)) | |
| } | |
| difficulty := os.Args[1] | |
| fmt.Fprintln(os.Stderr, "Called with difficulty:", difficulty) | |
| var wg sync.WaitGroup | |
| wg.Add(1) | |
| go gitMoney(difficulty, in, &wg) | |
| wg.Wait() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment