In python, pow(x,y,z)
is equivalent to (x**y)%z
, and the former is more efficient than the latter. But why is it useful? In which context does one routinely need to calculate such a quantity (or at least routinely enough for python developers to include it in the language)?
Asked
Active
Viewed 387 times
1

Lachy
- 218
- 1
- 5
-
1RSA encryption requires computing the value of large products modulo a given number. – chepner Sep 17 '17 at 15:43
1 Answers
2
This is famously useful for the RSA algorithm. If you try to use x**y%z
to encrypt or decrypt a message using RSA, it will be very slow or you could run out of memory, because x**y
is large.

Dietrich Epp
- 205,541
- 37
- 345
- 415
-
might be useful to add: https://stackoverflow.com/questions/14133806/why-is-powa-d-n-so-much-faster-than-ad-n – Daniel Heidemann Sep 17 '17 at 15:46