started c# pow implementation
This commit is contained in:
parent
3199f93d4b
commit
fd0f13cf63
7 changed files with 562 additions and 0 deletions
55
pow-csharp/onionrpow/OnionrPow.cs
Normal file
55
pow-csharp/onionrpow/OnionrPow.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using SHA3;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace onionrpow
|
||||
{
|
||||
public class OnionrPow
|
||||
{
|
||||
public static void compute(byte[] data, int difficulty){
|
||||
using (var shaAlg = SHA3.Net.Sha3.Sha3256())
|
||||
{
|
||||
// Replace beginning json with nonce
|
||||
int counter = 0;
|
||||
var copy = new List<byte>();
|
||||
|
||||
foreach(byte co in data){
|
||||
if (counter < 1){
|
||||
counter += 1;
|
||||
continue;
|
||||
//copy.Add(Encoding.UTF8.GetBytes("{\"pow\": "))
|
||||
}
|
||||
counter += 1;
|
||||
copy.Add(co);
|
||||
}
|
||||
int c = 0;
|
||||
while (true){
|
||||
toploop:
|
||||
c += 1;
|
||||
var num = Encoding.UTF8.GetBytes("{\"pow\": " + c.ToString() + ",");
|
||||
var copy2 = new List<byte>();
|
||||
|
||||
copy2.AddRange(num);
|
||||
copy2.AddRange(copy);
|
||||
var hash = shaAlg.ComputeHash(copy2.ToArray());
|
||||
|
||||
int counter2 = 0;
|
||||
foreach(byte one in hash){
|
||||
if ((int) one != 0){
|
||||
goto toploop;
|
||||
}
|
||||
counter2 += 1;
|
||||
if (counter2 == difficulty){
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.WriteLine(BitConverter.ToString(hash));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//b'{"meta":"{\\"ch\\":\\"global\\",\\"type\\":\\"brd\\"}","sig":"pR4qmKGGCdnyNyZRlhGfF9GC7bONCsEnY04lTfiVuTHexPJypOqmxe9iyDQQqdR+PB2gwWuNqGMs5O8\\/S\\/hsCA==","signer":"UO74AP5LGQFI7EJTN6NAVINIPU2XO2KA7CAS6KSWGWAY5XIB5SUA====","time":1600542238,"pow":300182}\nxcvxcvvxcxcv'
|
||||
}
|
||||
}
|
11
pow-csharp/onionrpow/onionrpow.csproj
Normal file
11
pow-csharp/onionrpow/onionrpow.csproj
Normal file
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SHA3.Net" Version="1.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue