summaryrefslogtreecommitdiff
path: root/rsa/core.py
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-01-22 11:36:06 +0100
committerSybren A. Stüvel <sybren@stuvel.eu>2016-01-22 11:36:06 +0100
commitd3d10345b47c2b17922bb91059cfceea82f82338 (patch)
tree6a336d74ee41a4ba98b6b3d97f123cd0c5f4e9b7 /rsa/core.py
parent541ee468b6b33c7ae27818bbfea63df9622f9d8a (diff)
downloadrsa-git-d3d10345b47c2b17922bb91059cfceea82f82338.tar.gz
Big refactor to become more PEP8 compliant.
Mostly focused on docstrings (''' → """), indentation, empty lines, and superfluous parenthesis.
Diffstat (limited to 'rsa/core.py')
-rw-r--r--rsa/core.py17
1 files changed, 8 insertions, 9 deletions
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
-