├── CSharp └── pow.cs ├── GO ├── pow.go └── pow_test.go ├── JS └── main.js ├── LICENSE ├── Python └── main.py ├── Readme.md ├── Rust ├── cargo.toml └── src │ └── main.rs └── TS └── main.ts /CSharp/pow.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | using System.Dynamic; 3 | using Newtonsoft.Json; 4 | 5 | public class POW 6 | { 7 | static string getHash(string input, int count) 8 | { 9 | dynamic json = new ExpandoObject(); 10 | json = new dynamic[10]; 11 | 12 | string padding = new string('0', count); 13 | 14 | for(int i = 0; i < 10; i++) 15 | { 16 | int postFix = 0; 17 | while (true) 18 | { 19 | postFix += 1; 20 | string encodedHash = BitConverter.ToString(new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(input + postFix.ToString()))).Replace("-", ""); 21 | if (encodedHash.IndexOf(padding) == 0) 22 | { 23 | json[i] = new ExpandoObject(); 24 | json[i].postfix = postFix; 25 | json[i].hash = encodedHash; 26 | break; 27 | } 28 | } 29 | } 30 | return Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(json))); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /GO/pow.go: -------------------------------------------------------------------------------- 1 | package queueit 2 | 3 | import ( 4 | "crypto/sha256" 5 | "encoding/hex" 6 | "strconv" 7 | ) 8 | 9 | type Solution struct { 10 | Postfix int64 `json:"postfix"` 11 | Hash string `json:"hash"` 12 | } 13 | 14 | func GetHash(input string, complexity, runs int) ([]Solution, error) { 15 | solutions := make([]Solution, runs) 16 | var postFix int64 17 | hash := sha256.New() 18 | var hashBytes [sha256.Size]byte 19 | 20 | inputBytes := []byte(input) 21 | postFixBytes := make([]byte, 0, 20) // all 64-bit integers will fit 22 | 23 | for i := 0; i < runs; i++ { 24 | for { 25 | hash.Reset() 26 | hash.Write(inputBytes) 27 | postFixBytes = strconv.AppendInt(postFixBytes[:0], postFix, 10) 28 | hash.Write(postFixBytes) 29 | hash.Sum(hashBytes[:0]) 30 | 31 | if checkZeroPrefix(hashBytes, complexity) { 32 | solutions[i] = Solution{ 33 | Postfix: postFix, 34 | Hash: hex.EncodeToString(hashBytes[:]), 35 | } 36 | postFix++ 37 | break 38 | } 39 | 40 | postFix++ 41 | } 42 | } 43 | 44 | return solutions, nil 45 | } 46 | 47 | // checkZeroPrefix checks if the first characters are all zeros in hexadecimal presentation 48 | func checkZeroPrefix(data [sha256.Size]byte, count int) bool { 49 | byteCount := (count + 1) / 2 50 | 51 | for i := 0; i < byteCount-1; i++ { 52 | if data[i] != 0x00 { 53 | return false 54 | } 55 | } 56 | 57 | if count%2 == 0 { 58 | if data[byteCount-1] != 0x00 { 59 | return false 60 | } 61 | } else { 62 | if (data[byteCount-1] & 0xf0) != 0x00 { 63 | return false 64 | } 65 | } 66 | 67 | return true 68 | } 69 | -------------------------------------------------------------------------------- /GO/pow_test.go: -------------------------------------------------------------------------------- 1 | package queueit 2 | 3 | import "testing" 4 | 5 | const ( 6 | input = "af085a5f-ae56-4450-8bf8-11cabf2b140a" 7 | zeroCount = 3 8 | runs = 25 9 | ) 10 | 11 | func TestGetHash(t *testing.T) { 12 | solution, err := GetHash(input, zeroCount, runs) 13 | if err != nil { 14 | t.Error(err) 15 | } else { 16 | t.Log(solution) 17 | } 18 | } 19 | 20 | func BenchmarkGetHash(b *testing.B) { 21 | b.ReportAllocs() 22 | for i := 0; i < b.N; i++ { 23 | if _, err := GetHash(input, zeroCount, runs); err != nil { 24 | b.Error(err) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /JS/main.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto') 2 | 3 | 4 | function getHash(input, paddingLength, runs) { 5 | let final = []; 6 | const padding = "0".repeat(paddingLength); 7 | let currentRuns = 0; 8 | for (let postFix = 0; true; postFix++) { 9 | const target = input + postFix.toString(), 10 | encodedHash = crypto.createHash("sha256").update(target).digest("hex"); 11 | if (encodedHash.indexOf(padding) === 0) { 12 | final.push({ 13 | postfix: postFix, 14 | hash: encodedHash, 15 | }); 16 | currentRuns++; 17 | } 18 | if (currentRuns === runs) { 19 | return final; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 IdekDude 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Python/main.py: -------------------------------------------------------------------------------- 1 | import hashlib 2 | 3 | def getHash(inputString: str, paddingLen: int, runs: int): 4 | results = [] 5 | padding = "0" * paddingLen 6 | currentRuns = 0 7 | 8 | postfix = 0 9 | while True: 10 | postfix += 1 11 | target = (inputString + str(postfix)).encode() 12 | encoded = hashlib.sha256(target).hexdigest() 13 | 14 | if encoded.startswith(padding): 15 | results.append({"postfix": postfix, "hash": encoded}) 16 | currentRuns += 1 17 | 18 | if currentRuns == runs: 19 | break 20 | 21 | return results 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Queue-it-Pow 2 | 3 | Queue It POW Solution in Various Langauges 4 | 5 | ## Usage 6 | 7 | ```javascript 8 | let input = "af085a5f-ae56-4450-8bf8-11cabf2b140a" 9 | let zeroCount = 3; 10 | let runs = 25; 11 | getHash(input, zeroCount, runs); 12 | ``` 13 | 14 | ```python 15 | input = "af085a5f-ae56-4450-8bf8-11cabf2b140a" 16 | zeroCount = 3 17 | runs = 25 18 | getHash(input, zeroCount, runs) 19 | ``` 20 | 21 | ```golang 22 | input := "f02b931c-52f0-4507-9406-f1221678dc16" 23 | zeroCount := 3 24 | runs := 25 25 | getHash(input, zeroCount, runs) 26 | ``` 27 | 28 | ```rs 29 | let input = "f02b931c-52f0-4507-9406-f1221678dc16"; 30 | let zero_count = 4; 31 | get_hash(input, zero_count); 32 | ``` 33 | 34 | ```cs 35 | string input = "f02b931c-52f0-4507-9406-f1221678dc16"; 36 | int zeroCount = 4; 37 | getHash(input, zeroCount) 38 | ``` 39 | 40 | ## Contributing 41 | 42 | Any and all pull requests are welcome. 43 | 44 | ## TODO 45 | - [X] Add Python 46 | - [X] Add Golang 47 | - [X] Add TS 48 | - [X] Add Rust 49 | - [X] Add C# 50 | 51 | ## Credits 52 | Python/Rust - [Cutty72](https://github.com/Cutty72) ([@72_cutty](https://twitter.com/72_cutty)) 53 |
54 | JS/TS - [IdekDude](https://github.com/IdekDude) ([@IdekDudeTbh](https://twitter.com/IdekDudeTbh)) 55 |
56 | C# - [LTPF](https://github.com/LTPF1337) ([@ltpf_dev](https://twitter.com/ltpf_dev)) 57 |
58 | Go - [KakashiHatake324](https://github.com/KakashiHatake324) ([@Rafi](https://twitter.com/rafuchiha)) 59 | 60 | ## License 61 | 62 | [MIT](https://choosealicense.com/licenses/mit/) 63 | -------------------------------------------------------------------------------- /Rust/cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "queue-pow" 3 | version = "1.0.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | crypto = { version = "0.3.0", features = ["digest"] } 8 | base64 = "0.13.0" 9 | serde = { version = "1.0.136", features = ["derive"] } 10 | serde_json = "1.0.79" 11 | sha2 = "0.10.2" 12 | -------------------------------------------------------------------------------- /Rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use sha2::{Digest}; 2 | use base64; 3 | use serde::Deserialize; 4 | use serde::Serialize; 5 | use serde_json; 6 | 7 | fn main() { 8 | let hash = get_hash("6fc83185-3a40-4737-a317-84f46405fa1f", 2); 9 | println!("{}", hash); 10 | } 11 | 12 | #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] 13 | #[serde(rename_all = "camelCase")] 14 | pub struct SolutionList { 15 | pub postfix: i32, 16 | pub hash: String, 17 | } 18 | 19 | fn get_hash(input: &str, padding_length: usize) -> String { 20 | let padding = "0".repeat(padding_length); 21 | let mut postfix: i32 = 0; 22 | loop { 23 | postfix += 1; 24 | let stri = input.to_owned() + &postfix.to_string(); 25 | let encoded_hash = gen_sha256(&stri); 26 | if encoded_hash.starts_with(&padding) { 27 | let list = SolutionList { 28 | postfix: postfix, 29 | hash: encoded_hash, 30 | }; 31 | let mut solution = [&list; 10]; 32 | for x in 0..10 { 33 | solution[x] = &list; 34 | } 35 | let serialized = serde_json::to_string(&solution).unwrap(); 36 | return base64::encode(serialized); 37 | } 38 | } 39 | } 40 | 41 | fn gen_sha256(hashme: &str) -> String { 42 | let mut hasher = sha2::Sha256::new(); 43 | hasher.update(hashme.as_bytes()); 44 | 45 | format!("{:X}", hasher.finalize()) 46 | } 47 | -------------------------------------------------------------------------------- /TS/main.ts: -------------------------------------------------------------------------------- 1 | import * as crypto from 'crypto' 2 | 3 | 4 | function getHash(input: string, paddingLength: number, runs: number) { 5 | let final: any[] = []; 6 | const padding = "0".repeat(paddingLength); 7 | let currentRuns = 0; 8 | for (let postFix = 0; true; postFix++) { 9 | const target = input + postFix.toString(), 10 | encodedHash = crypto.createHash("sha256").update(target).digest("hex"); 11 | if (encodedHash.indexOf(padding) === 0) { 12 | final.push({ 13 | postfix: postFix, 14 | hash: encodedHash, 15 | }); 16 | currentRuns++; 17 | } 18 | if (currentRuns === runs) { 19 | return final; 20 | } 21 | } 22 | } 23 | --------------------------------------------------------------------------------