Skip to content

Instantly share code, notes, and snippets.

@wengzilla
Forked from MichaelEvans/gist:8570324
Created January 23, 2014 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wengzilla/8570574 to your computer and use it in GitHub Desktop.
Save wengzilla/8570574 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/sha1"
"fmt"
"io"
"bytes"
"os"
"bufio"
"os/exec"
)
func sha(str string) string {
h := sha1.New()
io.WriteString(h, str)
return fmt.Sprintf("%x", h.Sum(nil))
}
// writeLines writes the lines to the given file.
func writeLines(line string, path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
w := bufio.NewWriter(file)
fmt.Fprintln(w, line)
return w.Flush()
}
func main(){
cmd := exec.Command("git", "write-tree")
tree, err := cmd.Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s", tree)
cmd = exec.Command("git", "rev-parse", "HEAD")
parent, err := cmd.Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s", parent)
s := `tree %s
parent %s
author CTF user <me@example.com> 1390424498 +0000
committer CTF user <me@example.com> 1390424498 +0000
Give me a Gitcoin
%d
`
counter := 0
for {
hash := sha(fmt.Sprintf(s, tree, parent, counter))
if bytes.Compare([]byte(hash), []byte("ff")) < 0{
fmt.Println(counter)
break
}
counter++
}
writeLines(fmt.Sprintf(s, tree, parent, counter), "output.txt")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment