Try to cast your 256 bit array to unsigned long mod_args[8];
std::string sha = sha256("10301231030456");
char hash[32];
for (int i = 0, j = 0; i < sha.length(); i += 2, j++)
{
std::string sub = sha.substr(i, 2);
hash[j] = strtoul(sub.c_str(), NULL, 16);
}
unsigned long mod_args[8];
memcpy(mod_args, hash, 32);
than getting 2 pieces of 64 bit:
unsigned long a = mod_args[1] ^ mod_args[3] ^ mod_args[5] ^ mod_args[7];
unsigned long b = mod_args[0] ^ mod_args[2] ^ mod_args[4] ^ mod_args[6];
than getting result by concat that two pieces
unsigned long long result = (((unsigned long long)a) << 32) | b;
or
unsigned long long result = (((unsigned long long)b) << 32) | a;
considering what piece of hash must be older a
or b
the complete solution is:
#define B_OLDER_THAN_A
int main()
{
std::string sha = sha256("10301231030456");
char hash[32];
for (int i = 0, j = 0; i < sha.length(); i += 2, j++)
{
std::string sub = sha.substr(i, 2);
hash[j] = strtoul(sub.c_str(), NULL, 16);
}
unsigned long mod_args[8];
memcpy(mod_args, hash, 32);
unsigned long a = mod_args[1] ^ mod_args[3] ^ mod_args[5] ^ mod_args[7];
unsigned long b = mod_args[0] ^ mod_args[2] ^ mod_args[4] ^ mod_args[6];
#ifdef B_OLDER_THAN_A
unsigned long long result = (((unsigned long long)b) << 32) | ((unsigned long long)a);
#else
unsigned long long result = (((unsigned long long)a) << 32) | ((unsigned long long)b);
#endif
unsigned char output[8] = { 0 };
memcpy(output, (char*)(&result), 8);
for (int i = 0; i < 8; i++)
std::cout << setfill('0') << setw(2) << hex << (unsigned int)(output[i]);
std::cout << endl;
return 0;
}