diff options
author | Haibo Huang <hhb@google.com> | 2020-07-29 01:06:32 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-07-29 01:06:32 +0000 |
commit | fba0d0316ff1cbf61c8d50e910afd9af9144534b (patch) | |
tree | 51130a47b9f85ff001627c9fdabf69dfc7293a1b /rsa/prime.py | |
parent | 70615f0491ec1dafe7302d863a49b6714a01166b (diff) | |
parent | 248aba47a609d40ca1fc9fce4e6ca35935ca71d1 (diff) | |
download | rsa-fba0d0316ff1cbf61c8d50e910afd9af9144534b.tar.gz |
Upgrade python/rsa to version-4.6 am: 248aba47a6
Original change: https://android-review.googlesource.com/c/platform/external/python/rsa/+/1361102
Change-Id: I8d5472cffe99a2d2f438b6d9e71a0b539eb61681
Diffstat (limited to 'rsa/prime.py')
-rw-r--r-- | rsa/prime.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/rsa/prime.py b/rsa/prime.py index 3d63542..853aca5 100644 --- a/rsa/prime.py +++ b/rsa/prime.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu> # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,14 +18,13 @@ Implementation based on the book Algorithm Design by Michael T. Goodrich and Roberto Tamassia, 2002. """ -from rsa._compat import range import rsa.common import rsa.randnum __all__ = ['getprime', 'are_relatively_prime'] -def gcd(p, q): +def gcd(p: int, q: int) -> int: """Returns the greatest common divisor of p and q >>> gcd(48, 180) @@ -39,7 +36,7 @@ def gcd(p, q): return p -def get_primality_testing_rounds(number): +def get_primality_testing_rounds(number: int) -> int: """Returns minimum number of rounds for Miller-Rabing primality testing, based on number bitsize. @@ -65,7 +62,7 @@ def get_primality_testing_rounds(number): return 10 -def miller_rabin_primality_testing(n, k): +def miller_rabin_primality_testing(n: int, k: int) -> bool: """Calculates whether n is composite (which is always correct) or prime (which theoretically is incorrect with error probability 4**-k), by applying Miller-Rabin primality testing. @@ -118,7 +115,7 @@ def miller_rabin_primality_testing(n, k): return True -def is_prime(number): +def is_prime(number: int) -> bool: """Returns True if the number is prime, and False otherwise. >>> is_prime(2) @@ -144,7 +141,7 @@ def is_prime(number): return miller_rabin_primality_testing(number, k + 1) -def getprime(nbits): +def getprime(nbits: int) -> int: """Returns a prime number that can be stored in 'nbits' bits. >>> p = getprime(128) @@ -172,7 +169,7 @@ def getprime(nbits): # Retry if not prime -def are_relatively_prime(a, b): +def are_relatively_prime(a: int, b: int) -> bool: """Returns True if a and b are relatively prime, and False if they are not. |