0
I was examining the block hashing algorithm and I tried to hash some blocks with my c++ sha256 to check results.
The hashes were wrong all the time so I thought I couldn't build the block header properly but then I took the data from wiki https://en.bitcoin.it/wiki/Block_hashing_algorithm and concatenated the values from the example and the result is still wrong (I tried it also in online sha-256 calculator so the function is ok).
Of course I must be missing something like coding but if I understand it right, sha is a function where you give a message and it takes the ascii codes of the message and does the math operations on these codes. But how can I pass a block header as a string? Or do I have to find an implementation of sha that interpretes the input differently?
I'm sorry, I know it's a noob question but this doesn't seem so obvious to me.
Edit:
The code is quite complex, but what I have at this moment is basically a made up block header that I packed in a string and for the example from the wiki page I mentioned above the string looks like
0100000081cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000e320b6c2
fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122bc7f5d74df2b9441a42a14695
I also have a sha function that takes a string as an input so the hash should be
1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000
but it's
cf5397ae292d5d37a0df81aa7f89f9fc7e1c43329e441ce2294f0a72e542c7d9
I also checked it on http://www.xorbin.com/tools/sha256-hash-calculator so I think the code is ok but I must just be missing something here.
Maybe it will help if you post your code and sample input. – Nate Eldredge – 2017-01-15T18:43:42.113
I tried a couple of wrong ways of doing it, and none of them match your output. Could you post the code? – Nick ODell – 2017-01-15T19:21:36.790
Do you want me to paste the whole sha implementation?? Check the link with the hash calculator and it shows the same output (it's the double sha, I've been comparing it with the real block hash, which I pasted above) – M-guy – 2017-01-15T19:34:45.273
Also your title (but not body) mentions mining. I hope you realize that anything programmable in C++ cannot mine bitcoin competively since about 5 years ago. – dave_thompson_085 – 2017-01-15T20:52:46.620
@dave_thompson_085 yup I do. – M-guy – 2017-01-15T21:14:12.110