dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 3e65e1687975c408d354091345907f45e74603c4
parent ec6398f7712ab32dd37131f179113fd0eead597e
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 27 May 2023 10:07:56 -0700

pow

Diffstat:
Acmd/pow/main.go | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/cmd/pow/main.go b/cmd/pow/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "crypto/sha256" + "encoding/hex" + "fmt" + "os" + "strconv" + "strings" +) + +func main() { + // ./pow n0tr1v + // 196598046 000000013f9472ce72d6ef66b10ff25db702a712484d72c157d52b260872686e + username := os.Args[1] + difficulty := 7 + prefix := strings.Repeat("0", difficulty) + var nonce int + var hashed string + for { + h := sha256.Sum256([]byte(username + "_" + strconv.Itoa(nonce))) + hashed = hex.EncodeToString(h[:]) + if strings.HasPrefix(hashed, prefix) { + fmt.Printf("%d %s\n", nonce, hashed) + return + } + nonce++ + } +}