You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The expmod function in §1.2.6 uses a subtlety. It is perhaps not immediately clear to (even careful) readers that for any three positive integers a, b, c, (ab) % c equals (r1r2) % c (where r1 = a % c and r2 = b % c).
Perhaps the main discussion around the function expmod should encourage readers to arrive at the above result (either through a footnote or through an exercise). Here is my humble attempt.
Relatedly, in exercise 1.25, we ask if Alyssa is correct in saying that fast_expt can effectively replace expmod. Whereas the answer provided there is correct, I believe that we need to establish if the remainder is not preserved in a two's complement notation even when the silent overflow occurs. I guess it is not preserved, and, as such, it is better to do r1r2 % c to reduce the likelihood of an overflow. I just feel that for the sake of completeness, we should mention this.
Another question: In the case of an odd exponent, shouldn't expmod be modified to
: ((base % m) * expmod(base, exp - 1, m))) % m;
(just for the sake of uniformity)?
The text was updated successfully, but these errors were encountered:
The
expmod
function in §1.2.6 uses a subtlety. It is perhaps not immediately clear to (even careful) readers that for any three positive integersa, b, c
,(ab) % c
equals(r1r2) % c
(wherer1 = a % c
andr2 = b % c
).Perhaps the main discussion around the function
expmod
should encourage readers to arrive at the above result (either through a footnote or through an exercise). Here is my humble attempt.Relatedly, in exercise 1.25, we ask if Alyssa is correct in saying that
fast_expt
can effectively replaceexpmod
. Whereas the answer provided there is correct, I believe that we need to establish if the remainder is not preserved in a two's complement notation even when the silent overflow occurs. I guess it is not preserved, and, as such, it is better to dor1r2 % c
to reduce the likelihood of an overflow. I just feel that for the sake of completeness, we should mention this.Another question: In the case of an odd exponent, shouldn't
expmod
be modified to(just for the sake of uniformity)?
The text was updated successfully, but these errors were encountered: