Skip to content

Instantly share code, notes, and snippets.

@cliffom
Last active December 15, 2017 18:59
Show Gist options
  • Save cliffom/a520f8de4564142b252939b847a492d2 to your computer and use it in GitHub Desktop.
Save cliffom/a520f8de4564142b252939b847a492d2 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"strconv"
)
func main() {
iterations, err := strconv.Atoi(os.Args[1])
if err != nil {
iterations = 1
}
data, _ := ioutil.ReadFile("rand.txt")
hash := getHash(data, iterations)
fmt.Printf("%x\n", hash)
}
func getHash(data []byte, iterations int) []byte {
for i := 0; i < iterations; i++ {
hash := sha256.New()
hash.Write(data)
data = hash.Sum(nil)
}
return data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment