On 01/20/10 22:23, Steven D'Aprano wrote:
I'm writing a module that handles, I won't call it encryption,
obfuscation using classical cryptographic algorithms. One of the
functions needs a deterministic but unpredictable integer generated from
a human-generated password or passphrase, so I'm usin
On Wed, 20 Jan 2010 19:27:34 +0100, Alf P. Steinbach wrote:
> * Mark Dickinson:
>> On Jan 20, 7:36 am, Steven D'Aprano > cybersource.com.au> wrote:
>>> I have a byte string (Python 2.x string), e.g.:
>>>
>>> s = "g%$f yg\n1\05"
>>> assert len(s) == 10
>>>
>>> I wish to convert it to a long integer
* Mark Dickinson:
On Jan 20, 7:36 am, Steven D'Aprano wrote:
I have a byte string (Python 2.x string), e.g.:
s = "g%$f yg\n1\05"
assert len(s) == 10
I wish to convert it to a long integer, treating it as base-256.
By the way, are you willing to divulge what you're using this
functionality f
On Jan 20, 7:36 am, Steven D'Aprano wrote:
> I have a byte string (Python 2.x string), e.g.:
>
> s = "g%$f yg\n1\05"
> assert len(s) == 10
>
> I wish to convert it to a long integer, treating it as base-256.
By the way, are you willing to divulge what you're using this
functionality for? When tr
Steven D'Aprano writes:
> s = "g%$f yg\n1\05"
> Is this the best way, or have I missed some standard library function?
It is really a shame that there is not a standard library function
for this. I usually do it using hexadecimal conversion:
d = int(s.encode('hex'), 16)
--
http://mail.python
On Jan 20, 7:36 am, Steven D'Aprano wrote:
> I have a byte string (Python 2.x string), e.g.:
>
> s = "g%$f yg\n1\05"
> assert len(s) == 10
>
> I wish to convert it to a long integer, treating it as base-256.
Not that it helps you right now, but provided someone finds the time,
there should be an
Steven D'Aprano wrote:
> I have a byte string (Python 2.x string), e.g.:
>
> s = "g%$f yg\n1\05"
> assert len(s) == 10
>
> I wish to convert it to a long integer, treating it as base-256.
> Currently I'm using:
>
> def makelong(s):
> n = 0
> for c in s:
> n *= 256
> n +=
Steven D'Aprano, 20.01.2010 08:36:
> I have a byte string (Python 2.x string), e.g.:
>
> s = "g%$f yg\n1\05"
> assert len(s) == 10
>
> I wish to convert it to a long integer, treating it as base-256.
> Currently I'm using:
>
> def makelong(s):
> n = 0
> for c in s:
> n *= 256
>
I have a byte string (Python 2.x string), e.g.:
s = "g%$f yg\n1\05"
assert len(s) == 10
I wish to convert it to a long integer, treating it as base-256.
Currently I'm using:
def makelong(s):
n = 0
for c in s:
n *= 256
n += ord(c)
return n
which gives:
>>> makelong