Last active
January 4, 2016 04:39
-
-
Save MichaelEvans/8570324 to your computer and use it in GitHub Desktop.
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 ( | |
"crypto/sha1" | |
"fmt" | |
"io" | |
"bytes" | |
"os/exec" | |
) | |
func sha(str string) string { | |
h := sha1.New() | |
io.WriteString(h, str) | |
return fmt.Sprintf("%x", h.Sum(nil)) | |
} | |
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 <[email protected]> 1390424498 +0000 | |
committer CTF user <[email protected]> 1390424498 +0000 | |
Give me a Gitcoin | |
%d | |
` | |
counter := 0 | |
for { | |
hash := sha(fmt.Sprintf(s, tree, parent, counter)) | |
if bytes.Compare([]byte(hash), []byte("000001")) < 0{ | |
fmt.Println(counter) | |
break | |
} | |
counter++ | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
prepare_index && git hash-object -t commit sample -w && git push origin master