How can we use pow
with a negative exponent in a modular context?
pow(x, y, [z]) If z is present, x and y must be of integer types, and y must be non-negative.
>>> pow(11444, -357)
0.0
>>> pow(11444, -357) % 48731
0.0
>>> pow(11444, -357, 48731)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: pow() 2nd argument cannot be negative when 3rd argument specified
In my use case, I want to encrypt a message using a Schnorr scheme:
y = (g ** -w) mod p
but pow
won't accept a negative number as the second argument here. As an example, from
g = 11444
p = 48731
w = 357
y
should be 7355
.