I want to do it in C# because it's my main language I do everything with and I do love WPF
It's your choice but you'll have to learn c anyway to port the algos to c#. And don't use scrypt, it's
no longer viable for CPU mining. Choose a CPU mineable algo.
Is there a simple algorithm to understand ?
I do not understand what this code is trying to do, what does meet the target means.
// Reference: https://github.com/replicon/Replicon.Cryptography.SCrypt
public void doScrypt(Byte[] Tempdata, Byte[] Target, uint Nonce, uint Increment)
{
var StartTime = DateTime.Now;
var Hashcount = 0.0;
var Databyte = new Byte[80];
Array.Copy(Tempdata, 0, Databyte, 0, 76);
// Loop until done is set or we meet the target
while (!done)
{
Databyte[76] = (Byte)(Nonce >> 0);
Databyte[77] = (Byte)(Nonce >> 8);
Databyte[78] = (Byte)(Nonce >> 16);
Databyte[79] = (Byte)(Nonce >> 24);
var ScryptResult = Replicon.Cryptography.SCrypt.SCrypt.DeriveKey(Databyte, Databyte, 1024, 1, 1, 32);
Hashcount++;
if (meetsTarget(ScryptResult, Target)) // Did we meet the target?
{
if (!done)
{
FinalNonce = Nonce;
}
done = true;
break;
}
else
{
Nonce += Increment; // If not, increment the nonce and try again
}
}
var Elapsedtime = (DateTime.Now - StartTime).TotalMilliseconds;
Console.WriteLine("Thread finished - {0:0} hashes in {1:0.00} ms. Speed: {2:0.00} kHash/s", Hashcount, Elapsedtime, Hashcount / Elapsedtime);
}
public bool meetsTarget(Byte[] Hash, Byte[] Target)
{
for (var Index = Hash.Length - 1; Index >= 0; Index--)
{
var ItemA = Hash[Index] & 0xFF;
var ItemB = Target[Index] & 0xFF;
if (ItemA > ItemB)
{
return false;
}
else if (ItemA < ItemB)
{
return true;
}
}
return false;
}