Re: xor: how come so slow?

2008-10-19 Thread Steven D'Aprano
On Sun, 19 Oct 2008 16:38:37 +1300, Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Steven D'Aprano wrote: On Sat, 18 Oct 2008 09:16:11 +1300, Lawrence D'Oliveiro wrote: Data can come in fractional bits. That's how compression works. If you don't believe me, try compressing a

Re: xor: how come so slow?

2008-10-19 Thread Steven D'Aprano
On Sun, 19 Oct 2008 04:38:04 +, Tim Roberts wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 17 Oct 2008 20:51:37 +1300, Lawrence D'Oliveiro wrote: Is piece really meant to be random? If so, your create_random_block function isn't achieving much--xoring random data together isn't

Re: xor: how come so slow?

2008-10-19 Thread MRAB
On Oct 19, 7:13 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Sun, 19 Oct 2008 04:38:04 GMT, Tim Roberts [EMAIL PROTECTED] declaimed the following in comp.lang.python: For those who got a bit lost here, I'd would point out that Knuth[1] has an excellent chapter on random numbers that

Re: xor: how come so slow?

2008-10-19 Thread Steve Holden
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Steven D'Aprano wrote: On Sat, 18 Oct 2008 09:16:11 +1300, Lawrence D'Oliveiro wrote: Data can come in fractional bits. That's how compression works. If you don't believe me, try compressing a single bit and see if you get a

Re: xor: how come so slow?

2008-10-19 Thread Aaron Brady
Steven D'Aprano wrote: On Sun, 19 Oct 2008 04:38:04 +, Tim Roberts wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 17 Oct 2008 20:51:37 +1300, Lawrence D'Oliveiro wrote: Is piece really meant to be random? If so, your create_random_block function isn't achieving much--xoring

Re: xor: how come so slow?

2008-10-19 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Steven D'Aprano wrote: On Sat, 18 Oct 2008 09:16:11 +1300, Lawrence D'Oliveiro wrote: Data can come in fractional bits. That's how compression works. If you don't believe me, try compressing a single

Re: xor: how come so slow?

2008-10-18 Thread Steven D'Aprano
On Fri, 17 Oct 2008 13:59:27 +0100, Sion Arrowsmith wrote: [I think these attributions are right] Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 17 Oct 2008 22:45:19 +1300, Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Steven D'Aprano wrote: ... why do you say that xoring

Re: xor: how come so slow?

2008-10-18 Thread Steven D'Aprano
On Sat, 18 Oct 2008 09:16:11 +1300, Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Sion Arrowsmith wrote: Maybe it should be fewer random data. Except these days we tend to think of data being, say, more like flour than bees, so it's less data, like less flour, rather than

Re: xor: how come so slow?

2008-10-18 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Steven D'Aprano wrote: On Sat, 18 Oct 2008 09:16:11 +1300, Lawrence D'Oliveiro wrote: Data can come in fractional bits. That's how compression works. If you don't believe me, try compressing a single bit and see if you get a fractional bit. If both states of

Re: xor: how come so slow?

2008-10-18 Thread Tim Roberts
Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 17 Oct 2008 20:51:37 +1300, Lawrence D'Oliveiro wrote: Is piece really meant to be random? If so, your create_random_block function isn't achieving much--xoring random data together isn't going to produce anything more exciting than less random

Re: xor: how come so slow?

2008-10-17 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Michele wrote: class Encoder(object): def create_random_block(self, data, seed, blocksize): number_of_blocks = int(len(data)/blocksize) random.seed(seed) random_block = ['0'] * blocksize for index in range(number_of_blocks):

Re: xor: how come so slow?

2008-10-17 Thread Steven D'Aprano
On Fri, 17 Oct 2008 20:51:37 +1300, Lawrence D'Oliveiro wrote: Is piece really meant to be random? If so, your create_random_block function isn't achieving much--xoring random data together isn't going to produce anything more exciting than less random data than you started with. Hmmm...

Re: xor: how come so slow?

2008-10-17 Thread Paul Rubin
Michele [EMAIL PROTECTED] writes: I suppose that ord() and char() are the main problems yes How should I decrease the execution time? See http://nightsong.com/phr/crypto/p3.py which deals with the same problem by using the array module to do the xor's 32 bits at a time. --

Re: xor: how come so slow?

2008-10-17 Thread Steven D'Aprano
On Fri, 17 Oct 2008 22:45:19 +1300, Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Steven D'Aprano wrote: On Fri, 17 Oct 2008 20:51:37 +1300, Lawrence D'Oliveiro wrote: ... why do you say that xoring random data with other random data produces less randomness than you started

Re: xor: how come so slow?

2008-10-17 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Steven D'Aprano wrote: On Fri, 17 Oct 2008 20:51:37 +1300, Lawrence D'Oliveiro wrote: ... why do you say that xoring random data with other random data produces less randomness than you started with? blocksize = number_of_blocks * blocksize --

Re: xor: how come so slow?

2008-10-17 Thread Sion Arrowsmith
[I think these attributions are right] Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 17 Oct 2008 22:45:19 +1300, Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Steven D'Aprano wrote: ... why do you say that xoring random data with other random data produces less randomness than

Re: xor: how come so slow?

2008-10-17 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Sion Arrowsmith wrote: Maybe it should be fewer random data. Except these days we tend to think of data being, say, more like flour than bees, so it's less data, like less flour, rather than like fewer bees. :) After all, each byte in the block is discrete. Data

Re: xor: how come so slow?

2008-10-15 Thread John Machin
On Oct 15, 10:19 pm, Michele [EMAIL PROTECTED] wrote: Hi, I'm trying to encode a byte data. Let's not focus on the process of encoding; in fact, I want to emphasize that the method create_random_block takes 0.5s to be executed (even Java it's faster) on a Dual-Core 3.0Ghz machine: took

xor: how come so slow?

2008-10-15 Thread Michele
Hi, I'm trying to encode a byte data. Let's not focus on the process of encoding; in fact, I want to emphasize that the method create_random_block takes 0.5s to be executed (even Java it's faster) on a Dual-Core 3.0Ghz machine: took 46.74679s, avg: 0.4674679s Thus I suppose that the xor

Re: xor: how come so slow?

2008-10-15 Thread Seun Osewa
My answer is: never do things like this with python. You will find this module useful: www.pycrypto.org On Oct 15, 12:19 pm, Michele [EMAIL PROTECTED] wrote: Hi, I'm trying to encode a byte data. Let's not focus on the process of encoding; in fact, I want to emphasize that the method

Re: xor: how come so slow?

2008-10-15 Thread bearophileHUGS
Few suggestions for your code: - Use xrange instead of range. - Loop over lists where you can instead of their indexes. - array.array(B, somestring) may help you because it gives a byte view of a string. - Using psyco helps a lot for such kind of code. - I think numpy arrays can contain text/chars

Re: xor: how come so slow?

2008-10-15 Thread Peter Otten
Michele wrote: I'm trying to encode a byte data. Let's not focus on the process of encoding; in fact, I want to emphasize that the method create_random_block takes 0.5s to be executed (even Java it's faster) on a Dual-Core 3.0Ghz machine: took 46.74679s, avg: 0.4674679s How