pow-help.gohtml (1382B)
1 {{ define "title" }}dkf - pow help{{ end }} 2 3 {{ define "content" }} 4 5 <div class="container"> 6 <div> 7 8 <h3>Proof of work help</h3> 9 10 <p> 11 To calculate the POW, you have to compute a suffix such that 12 the sha256 of <code>username:suffix</code> starts with seven zeros. 13 </p> 14 <p> 15 For example, the sha256 of <code>my_username:69395289</code> is<br /> 16 <code><strong>0000000</strong>688a8637a52bd0f295e505cd85156ea2c403aa633e200cf73b4915cf1</code><br /> 17 which starts with seven zeros, so your proof of work would be <code>69395289</code> 18 </p> 19 20 <p> 21 You can use the following script to calculate the proof of work: 22 </p> 23 24 <pre style="border: 1px solid #5d5d5d; padding: 5px;"><code>package main 25 26 import ( 27 "crypto/sha256" 28 "encoding/hex" 29 "fmt" 30 "os" 31 "strconv" 32 "strings" 33 ) 34 35 // Build with `go build -o pow main.go` 36 // Use `./pow my_username` 37 func main() { 38 username := os.Args[1] 39 difficulty := {{ .Data.Difficulty }} 40 prefix := strings.Repeat("0", difficulty) 41 var nonce int 42 for { 43 h := sha256.Sum256([]byte(username + ":" + strconv.Itoa(nonce))) 44 hashed := hex.EncodeToString(h[:]) 45 if strings.HasPrefix(hashed, prefix) { 46 fmt.Printf("%s:%d -> %s\n", username, nonce, hashed) 47 return 48 } 49 nonce++ 50 } 51 } 52 </code></pre> 53 54 </div> 55 </div> 56 57 {{ end }}