I've been deep in the weeds of sha256, with Python3, while working on a Python implementation of the DIY Bitcoin Private Key Project In fact, if there's any coders here, maybe you could help me out:
I first want to get to grips with the Python sha256 function, so that I can move on to the more complex operation of generating the 24th BIP0039 seed word, for which I need the first 8 bits of the sha256 check sum that's derived by hashing the entire 256 bit key.
So, the basics first: I don't understand (as an example) why... $ echo R | shasum -a 256 -t ... returns... 13b30eab8afdfab285103004686b2e6140ce53aa45a4f917341c740dfdb6e956 ... while... print(sha256('R'.encode('utf-8')).hexdigest()) ... returns... 8c2574892063f995fdf756bce07f46c1a5193e54cd52837ed91e32008ccf41ac
Once I get this nailed down, I can move on the the more complex task.
With thanks to both @k00b and @039802da15
For anyone following this, the correct cli command would be... echo -n R | shasum -a 256 -t
reply
Echo adds a newline to the output, see https://stackoverflow.com/a/34430808
So your first command is actually hashing "R\n" while the 2nd one is hashing "R"
reply
@k00b and @039802da15 My thanks to you both (a bit of a 'head slap' moment for me!). The cli echo commend is in fact directly from the Bitcoinmagazine feature, so I'm now thinking that it's an incorrect method. Time will tell, because if the checksum is not correct, a Wallet such as Sparrow will not accept the 24 Word Seed. I know that the Electrum Wallet does not do that check (I've tried it), so any random collection of 24 BIP0039 Seed Words will work. Thanks again; back to it :)
reply
echo appends a newline.
>>> print(sha256('R\n'.encode('utf-8')).hexdigest()) 13b30eab8afdfab285103004686b2e6140ce53aa45a4f917341c740dfdb6e956
reply