├── LICENSE ├── README.md └── main.py /LICENSE: -------------------------------------------------------------------------------- 1 | # Queue-it Proof-of-Work 2 | 3 | [![Go Reference](https://pkg.go.dev/badge/github.com/etaaa/Queue-it-Proof-of-Work.svg)](https://pkg.go.dev/github.com/etaaa/Queue-it-Proof-of-Work) 4 | [![Go Report Card](https://goreportcard.com/badge/github.com/etaaa/Queue-it-Proof-of-Work)](https://goreportcard.com/report/github.com/etaaa/Queue-it-Proof-of-Work) 5 | 6 | A Golang solution for Queue-it's Proof-of-Work challenge (). 7 | 8 | ## Usage 9 | 10 | Install: 11 | ```bash 12 | go get github.com/etaaa/Queue-it-Proof-of-Work 13 | ``` 14 | Usage: 15 | ```bash 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | pow "github.com/etaaa/Queue-it-Proof-of-Work" 21 | ) 22 | 23 | func main() { 24 | /* GET THESE VALUES FROM THE RESPONSE WHEN FETCHING 25 | THE CHALLENGE AT .../challengeapi/pow/challenge/... */ 26 | input := "f02b931c-52f0-4507-9406-f1221678dc16" 27 | zeroCount := 2 28 | // RETURNS THE CHALLENGE SOLUTION 29 | solution := pow.SolveChallenge(input, zeroCount) 30 | fmt.Println(solution) 31 | } 32 | ``` 33 | 34 | ## Questions 35 | For any questions feel free to add and DM me on Discord (eta#0001). 36 | 37 | ## Contributing 38 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate. 39 | 40 | ## License 41 | [MIT](https://choosealicense.com/licenses/mit/) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Queue-it Proof-of-Work 2 | 3 | A Python solution for Queue-it's Proof-of-Work challenge (). 4 | 5 | ## Usage 6 | 7 | Usage: 8 | ```python 9 | import base64, hashlib, json 10 | 11 | def solveChallenge(input, zeroCount): 12 | zeros = "0" * zeroCount 13 | postfix = 0 14 | while True: 15 | postfix += 1 16 | stri = input + str(postfix) 17 | encodedHash = hashlib.sha256(stri.encode()).hexdigest() 18 | if encodedHash.startswith(zeros): 19 | x = 10 * [{ "hash": encodedHash,"postfix": postfix }] 20 | return base64.b64encode(json.dumps(x, separators=(',', ':')).encode()).decode() 21 | 22 | # GET THESE VALUES FROM THE RESPONSE WHEN FETCHING 23 | # THE CHALLENGE AT .../challengeapi/pow/challenge/... 24 | input = "f02b931c-52f0-4507-9406-f1221678dc16" 25 | zeroCount = 2 26 | # RETURNS THE CHALLENGE SOLUTION 27 | solution = solveChallenge(input, zeroCount) 28 | print(solution) 29 | ``` 30 | 31 | ## Questions 32 | For any questions feel free to add and DM me on Discord (eta#1656). 33 | 34 | ## Contributing 35 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate. 36 | 37 | ## License 38 | [MIT](https://choosealicense.com/licenses/mit/) 39 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import base64, hashlib, json 2 | 3 | def solveChallenge(input, zeroCount): 4 | zeros = "0" * zeroCount 5 | postfix = 0 6 | while True: 7 | postfix += 1 8 | stri = input + str(postfix) 9 | encodedHash = hashlib.sha256(stri.encode()).hexdigest() 10 | if encodedHash.startswith(zeros): 11 | x = 10 * [{ "hash": encodedHash,"postfix": postfix }] 12 | return base64.b64encode(json.dumps(x, separators=(',', ':')).encode()).decode() 13 | 14 | # GET THESE VALUES FROM THE RESPONSE WHEN FETCHING 15 | # THE CHALLENGE AT .../challengeapi/pow/challenge/... 16 | input = "f02b931c-52f0-4507-9406-f1221678dc16" 17 | zeroCount = 2 18 | # RETURNS THE CHALLENGE SOLUTION 19 | solution = solveChallenge(input, zeroCount) 20 | print(solution) --------------------------------------------------------------------------------