From d3d10345b47c2b17922bb91059cfceea82f82338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 22 Jan 2016 11:36:06 +0100 Subject: =?UTF-8?q?Big=20refactor=20to=20become=20more=20PEP8=20compliant.?= =?UTF-8?q?=20Mostly=20focused=20on=20docstrings=20('''=20=E2=86=92=20""")?= =?UTF-8?q?,=20indentation,=20empty=20lines,=20and=20superfluous=20parenth?= =?UTF-8?q?esis.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsa/core.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'rsa/core.py') diff --git a/rsa/core.py b/rsa/core.py index 90dfee8..9b5c107 100644 --- a/rsa/core.py +++ b/rsa/core.py @@ -14,24 +14,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -'''Core mathematical operations. +"""Core mathematical operations. This is the actual core RSA implementation, which is only defined mathematically on integers. -''' - +""" from rsa._compat import is_integer -def assert_int(var, name): +def assert_int(var, name): if is_integer(var): return raise TypeError('%s should be an integer, not %s' % (name, var.__class__)) + def encrypt_int(message, ekey, n): - '''Encrypts a message using encryption key 'ekey', working modulo n''' + """Encrypts a message using encryption key 'ekey', working modulo n""" assert_int(message, 'message') assert_int(ekey, 'ekey') @@ -39,15 +39,15 @@ def encrypt_int(message, ekey, n): if message < 0: raise ValueError('Only non-negative numbers are supported') - + if message > n: raise OverflowError("The message %i is too long for n=%i" % (message, n)) return pow(message, ekey, n) + def decrypt_int(cyphertext, dkey, n): - '''Decrypts a cypher text using the decryption key 'dkey', working - modulo n''' + """Decrypts a cypher text using the decryption key 'dkey', working modulo n""" assert_int(cyphertext, 'cyphertext') assert_int(dkey, 'dkey') @@ -55,4 +55,3 @@ def decrypt_int(cyphertext, dkey, n): message = pow(cyphertext, dkey, n) return message - -- cgit v1.2.1