summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. St?vel <sybren@stuvel.eu>2011-06-20 00:14:03 +0200
committerSybren A. St?vel <sybren@stuvel.eu>2011-06-20 00:14:03 +0200
commit1f84144ac55a9783257bce1ed9eb54d87ec511e0 (patch)
treeed8fb69bb50a9ea75f1b44456cb195c1aafa35c2
parenta65be432dd6f69331bc5126c5f81399c82e8fce8 (diff)
downloadrsa-1f84144ac55a9783257bce1ed9eb54d87ec511e0.tar.gz
Clarified some code
-rwxr-xr-xrsa/__init__.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/rsa/__init__.py b/rsa/__init__.py
index e132989..3aef6d8 100755
--- a/rsa/__init__.py
+++ b/rsa/__init__.py
@@ -147,7 +147,8 @@ def encode64chops(chops):
chips = [] #chips are character chops
for value in chops:
- chips.append(rsa.transform.int2str64(value))
+ as_str = rsa.transform.int2str64(value)
+ chips.append(as_str)
#delimit chops with comma
encoded = ','.join(chips)
@@ -162,25 +163,29 @@ def decode64chops(string):
chops = []
for string in chips: #make char chops (chips) into chops
- chops.append(rsa.transform.str642int(string))
+ as_int = rsa.transform.str642int(string)
+ chops.append(as_int)
return chops
-def chopstring(message, key, n, funcref):
- """Chops the 'message' into integers that fit into n,
- leaving room for a safebit to be added to ensure that all
- messages fold during exponentiation. The MSB of the number n
- is not independant modulo n (setting it could cause overflow), so
- use the next lower bit for the safebit. Therefore reserve 2-bits
- in the number n for non-data bits. Calls specified encryption
- function for each chop.
+def chopstring(message, key, n, int_op):
+ """Chops the 'message' into integers that fit into n.
+
+ Leaves room for a safebit to be added to ensure that all messages fold
+ during exponentiation. The MSB of the number n is not independent modulo n
+ (setting it could cause overflow), so use the next lower bit for the
+ safebit. Therefore this function reserves 2 bits in the number n for
+ non-data bits.
+
+ Calls specified encryption function 'int_op' for each chop before storing.
Used by 'encrypt' and 'sign'.
"""
msglen = len(message)
mbits = msglen * 8
- #Set aside 2-bits so setting of safebit won't overflow modulo n.
+
+ # Set aside 2 bits so setting of safebit won't overflow modulo n.
nbits = bit_size(n) - 2 # leave room for safebit
nbytes = nbits / 8
blocks = msglen / nbytes
@@ -194,7 +199,7 @@ def chopstring(message, key, n, funcref):
offset = bindex * nbytes
block = message[offset:offset+nbytes]
value = rsa.transform.bytes2int(block)
- cypher.append(funcref(value, key, n))
+ cypher.append(int_op(value, key, n))
return encode64chops(cypher) #Encode encrypted ints to base64 strings