1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Add tests of modpow.

[originally from svn r9100]
This commit is contained in:
Simon Tatham
2011-02-20 15:27:48 +00:00
parent 1b47322c3b
commit 15d7f8bb3e
2 changed files with 71 additions and 8 deletions

11
testdata/bignum.py vendored
View File

@ -77,6 +77,13 @@ def hexstr(n):
# carry to the very top of the number.
for i in range(1,4200):
a, b, p = findprod((1<<i)+1, +1, (i, i*i+1))
print hexstr(a), hexstr(b), hexstr(p)
print "mul", hexstr(a), hexstr(b), hexstr(p)
a, b, p = findprod((1<<i)+1, +1, (i, i+1))
print hexstr(a), hexstr(b), hexstr(p)
print "mul", hexstr(a), hexstr(b), hexstr(p)
# Simple tests of modpow.
for i in range(64, 4097, 63):
modulus = mathlib.sqrt(1<<(2*i-1)) | 1
base = mathlib.sqrt(3*modulus*modulus) % modulus
expt = mathlib.sqrt(modulus*modulus*2/5)
print "pow", hexstr(base), hexstr(expt), hexstr(modulus), hexstr(pow(base, expt, modulus))