SHA-based subclass for random module
Raymond Hettinger
python at rcn.com
Thu Mar 25 05:07:58 EST 2004
> > What might be nice is if longs had methods for converting to and from
> > bytestrings.
>
> I was thinking the same. How about something like:
>
> bigNumber = long(bigNumberString, 256)
>
> bigNumberString = bigNumber.tostring()
>
> The string->long conversion treats a big-endian byte string as "base
> 256", and converts it to a non-negative integer.
>
> The long->string conversion would only work on non-negative integers.
> It's 'inspired' by the array module's "tostring()" method, which returns
> a similarly low-level string.
>
> Big-endian seems the common way to do this, at least in cryptography, in
> the common ASN.1 encodings, and in the libraries I've seen.
If this is something you want, file a feature request on SF.
Raymond
More information about the Python-list
mailing list