2
$\begingroup$

I'm reading Cryptography And Network Security of William Stallings.

In the SHA-512 section it is said that there is a 512-bit buffer is used to hold the intermediate and final result and every 64-bit obtained somehow (obtained by taking the first sixty-four bits of the fractional parts of the square roots of the first eight prime numbers).

However, if I convert the first of the binary digits to base 10 I get:

a = 7640891576956012808

I searched the square root of 2 in high precision( https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil ) and did not match. Why?

$\endgroup$
  • $\begingroup$ Which edition are we talking about and the page is? Here the SHA2, NIST under maintenance. $\endgroup$ – kelalaka Oct 26 '19 at 16:20
  • $\begingroup$ seventh edition.end of page 357 and beginning of 358 $\endgroup$ – naweed Oct 27 '19 at 6:50
2
$\begingroup$

What you've done is to shift the 64 bits that you require to the left, before printing out the values. So instead of looking at the bits directly, you are looking at a shifted representation of them. However, if you do that you multiply with a power of two, not a power of ten.

To be precise, if you shift 64 bits to the left then you multiply with $$2^{64} = 18,446,744,073,709,551,616$$ Of course, this number is far from a power of 10, so you would expect it to skew if you look at the result in decimals.

And if you look at the value then you'll see that it is indeed about 1,85 times the number you expect. You get a 7 something instead of a 4 something. In case you don't trust me, here's an interesting calculation for you...

In other words, you interpret the binary digits as if they are digits at the left of the dot, rather than at the right of the dot when you converted them to decimal. It matters where the dot is when you do base conversion and you want to look at the digits.

$\endgroup$
  • $\begingroup$ I.e. the a you've calculated has the right value (congrats), just convert to hexadecimals or bytes. $\endgroup$ – Maarten Bodewes Oct 27 '19 at 0:56
  • $\begingroup$ yea, I found out my mistake. $\endgroup$ – naweed Oct 28 '19 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.