Kayode Odeyemi wrote: > On Sat, Oct 8, 2011 at 12:50 AM, Terry Reedy <tjre...@udel.edu> wrote: > >> That latter function probably want integers code in range(256). > > > Yes! Non-unicode. The source reads: > > def _encrypt(self, m): > # compute m**d (mod n) > return pow(m, self.e, self.n) > >>From the source, it is provided as is. > > The arguments must have numeric types >> > > How come it accepts str type?
pow() does not accept a str. Most likely there is conversion code similar to if isinstance(m, str): m = convert_to_int(m) that precedes the _encrypt() method call and lets unicode slip through. Grepping through the PyCrypto source for isinstance indeed finds a few candidates. Example: $ find . -name \*.py | xargs grep isinstance -A5 [...] ./PublicKey/pubkey.py: if isinstance(plaintext, types.StringType): ./PublicKey/pubkey.py- plaintext=bytes_to_long(plaintext) ; wasString=1 ./PublicKey/pubkey.py: if isinstance(K, types.StringType): ./PublicKey/pubkey.py- K=bytes_to_long(K) ./PublicKey/pubkey.py- ciphertext=self._encrypt(plaintext, K) ./PublicKey/pubkey.py- if wasString: return tuple(map(long_to_bytes, ciphertext)) ./PublicKey/pubkey.py- else: return ciphertext ./PublicKey/pubkey.py- [...] -- http://mail.python.org/mailman/listinfo/python-list