As with King, just doing this for fun and learning, no dillusions that an Arduino is effective mining hardware.
Thanks.
#include "sha256.h"
void setup() {
Serial.begin(57600);
}
void loop() {
String data = "00000001c570c4764aadb3f09895619f549000b8b51a789e7f58ea750000709700000000103ca064f8c76c390683f8203043e91466a7fcc40e6ebc428fbcc2d89b574a864db8345b1b00b5ac00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000";
data = RemovePadding(data);
data = EndianFlip32BitChunks(data); //flips from little endian to big endian
Sha256.init();
Sha256.print(data.substring(0,80)); //hash first half to make midstate
uint8_t* midstatearray = Sha256.result();
Serial.println(F("Calc midstate is:"));
printHash(midstatearray);
Serial.println(F("Expected:"));
Serial.println(F("e772fc6964e7b06d8f855a6166353e48b2562de4ad037abc889294cea8ed1070"));
}
void printHash(uint8_t* hash) {
int i;
for (i=0; i<32; ++i) {
Serial.print("0123456789abcdef"[hash[i]>>4]);
Serial.print("0123456789abcdef"[hash[i]&0xf]);
}
Serial.println();
}
static String EndianFlip32BitChunks(String input)
{
//32 bits = 4*4 bytes = 4*4*2 chars
String result = "";
for (int i = 0; i < input.length(); i += 8)
for (int j = 0; j < 8; j += 2)
{
//append byte (2 chars)
result += input[i - j + 6];
result += input[i - j + 7];
}
return result;
}
static String RemovePadding(String input)
{
//payload length: final 64 bits in big-endian - 0x0000000000000280 = 640 bits = 80 bytes = 160 chars
return input.substring(0, 160);
}