From: Loup Vaillant Date: Tue, 18 Feb 2020 17:25:11 +0000 (+0100) Subject: Use pow() for exponentiation in Python 3 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=8a3b2fbce72cdb926e80cd6a77f659c8dd992ee6;p=Monocypher.git Use pow() for exponentiation in Python 3 Much faster this way. --- diff --git a/tests/gen/elligator.py b/tests/gen/elligator.py index acb13d5..5f4e91b 100755 --- a/tests/gen/elligator.py +++ b/tests/gen/elligator.py @@ -69,21 +69,8 @@ def print_little(n): def binary(b): return [int(c) for c in list(format(b, 'b'))] -def exp(a, b): - """ - a^b mod p - b must be positive - """ - d = 1 - for i in binary(b): - d = (d*d) % p - if i == 1: - d = (d*a) % p - return d - -def invert(n): - """Modular invert of n""" - return exp(n, p-2) +def exp(a, b): return pow(a, b, p) +def invert(n): return exp(n, p-2) def m_abs(n): """Modular absolute value of n, to canonicalise square roots."""