c# pow implementation work

This commit is contained in:
Kevin Froman 2020-09-20 21:13:46 +00:00
parent 60c1ec07e9
commit 499981ed52
5 changed files with 34 additions and 8 deletions

View file

@ -1,5 +1,7 @@
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
using onionrpow;
@ -9,8 +11,18 @@ namespace onionrpow_cli
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
onionrpow.OnionrPow.compute(Encoding.UTF8.GetBytes("test"), 4);
using (Stream stdin = Console.OpenStandardInput())
{
var data = new List<byte>();
byte[] buffer = new byte[60000];
int bytes;
while ((bytes = stdin.Read(buffer, 0, buffer.Length)) > 0) {
//stdout.Write(buffer, 0, bytes);
data.AddRange(buffer);
}
onionrpow.OnionrPow.compute(data.ToArray(), 3);
}
}
}
}

View file

@ -11,7 +11,7 @@ namespace onionrpow
public static void compute(byte[] data, int difficulty){
using (var shaAlg = SHA3.Net.Sha3.Sha3256())
{
// Replace beginning json with nonce
// Replace beginning json with counter
int counter = 0;
var copy = new List<byte>();
@ -25,12 +25,12 @@ namespace onionrpow
copy.Add(co);
}
int c = 0;
var copy2 = new List<byte>();
while (true){
toploop:
c += 1;
var num = Encoding.UTF8.GetBytes("{\"pow\": " + c.ToString() + ",");
var copy2 = new List<byte>();
copy2.Clear();
copy2.AddRange(num);
copy2.AddRange(copy);
var hash = shaAlg.ComputeHash(copy2.ToArray());
@ -45,7 +45,9 @@ namespace onionrpow
break;
}
}
Console.WriteLine(Encoding.UTF8.GetString(copy2.ToArray()));
Console.WriteLine(BitConverter.ToString(hash));
Console.WriteLine(c);
break;
}
}