Question
C++ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //batcoin.h #ifndef BATCOIN_H #define BATCOIN_H #include using namespace std; class BlockHeader { public: // Initializes a new BlockHeader to all zeroes BlockHeader(); //
C++
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//batcoin.h
#ifndef BATCOIN_H #define BATCOIN_H #includeusing namespace std; class BlockHeader { public: // Initializes a new BlockHeader to all zeroes BlockHeader(); // Returns a string representation of the BlockHeader values. // For example: // // prev: 114 64 204 51 183 55 8 239 // nonce: 39 196 114 213 34 95 241 38 // string to_string(); // These store 8 bytes of information each, // storing each byte as an unsigned char. unsigned char prev[8]; // Previous BlockHeader hash value unsigned char nonce[8]; // The nonce for this BlockHeader }; // The hash function used in the Batcoin protocol. void bathash(BlockHeader b, unsigned char* result); #endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//batcoin.cpp
#include#include "batcoin.h" using namespace std; BlockHeader :: BlockHeader() { for (int i = 0; i > 1) ^ (result[0] >> 3) ^ (result[0] >> 6); T[3] = (result[4] >> 2) ^ (result[4] >> 5) ^ (result[4] >> 7); result[3] = result[3] + result[7] + T[0] + T[3]; T[4] = result[7] + T[0] + T[1] + T[2] + T[3]; for (int i = 6; i >= 0; --i) result[i+1] = result[i]; result[0] = T[4]; } } //////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//mine.h
#ifndef MINE_H #define MINE_H #include "batcoin.h" // Returns a BlockHeader whose prev bytes are equal to the // output of bathash(prev) and that hashes to a set of bytes // where the first difficulty of them are equal to 0. BlockHeader mine(BlockHeader prev, int difficulty); #endif
#include#include "batcoin.h" #include "mine.h" using namespace std; inline void _test(const char* expression, const char* file, int line) { cerr /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//mine.cpp
#include "mine.h"
// Returns a BlockHeader whose prev bytes are equal to the
// output of bathash(prev) and that hashes to a set of bytes
// where the first difficulty of them are equal to 0.
BlockHeader mine(BlockHeader prev, int difficulty)
{
BlockHeader b;
unsigned char result[8];
int dif = 0;
bathash(prev, result);
b.prev;
for (int i = 0; i
{
b.prev[i] = result[i];
}
for (int i = 0; i
{
b.nonce[i] = 0;
}
while (true)
{
bathash(b, result);
if (difficulty == 1)
{
if (b.nonce[0] == 0)
{
return b;
}
}
if (difficulty == 2)
{
}
if (difficulty == 3)
{
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started