Re: Convert to binary and convert back to strings

2007-02-24 Thread Paul Rubin
"Hendrik van Rooyen" <[EMAIL PROTECTED]> writes: > > s += chr(reduce(operator.xor, ar)) > Yikes! - someday soon I am going to read the docs on what reduce does... Reduce just intersperses an operator over a sequence. For example, reduce(operator.add, (a,b,c,d,e)) is a+b+c+d+e. > Won't this

Re: Convert to binary and convert back to strings

2007-02-24 Thread Hendrik van Rooyen
"Paul Rubin" wrote: > "Hendrik van Rooyen" <[EMAIL PROTECTED]> writes: > > s = 'some string that needs a bcc appended' > > ar = array.array('B',s) > > bcc = 0 > > for x in ar[:]: > > bcc ^= x > > ar.append(bcc) > > s=ar.tostring() > > Untested: > > import operator

Re: Convert to binary and convert back to strings

2007-02-23 Thread Eric Pederson
Harlin Seritt wrote: >Hi... > >I would like to take a string like 'supercalifragilisticexpialidocius' >and write it to a file in binary forms -- this way a user cannot read >the string in case they were try to open in something like ascii text >editor. I'd also like to be able to read the binary f

Re: Convert to binary and convert back to strings

2007-02-23 Thread Mikael Olofsson
Neil Cerutti wrote: > Woah! You better quadruple it instead. > How about Double Pig Latin? > No, wait! Use the feared UDPLUD code. > You go Ubbi Dubbi to Pig Latin, and then Ubbi Dubbi again. > Let's see here... Ubububythubububonubpubay > That's what I call ubububeautubububifubububulbubay. That

Re: Convert to binary and convert back to strings

2007-02-22 Thread Paul Rubin
"Hendrik van Rooyen" <[EMAIL PROTECTED]> writes: > s = 'some string that needs a bcc appended' > ar = array.array('B',s) > bcc = 0 > for x in ar[:]: > bcc ^= x > ar.append(bcc) > s=ar.tostring() Untested: import operator s = 'some string that needs a bcc appended' ar = array.array('B',s) s +=

Re: Convert to binary and convert back to strings

2007-02-22 Thread Hendrik van Rooyen
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > On Thu, 22 Feb 2007 08:18:07 +0200, Hendrik van Rooyen wrote: > > > I would xor each char in it with 'U' as a mild form of obfuscation... > > I've often wished this would work. > > >>> 'a' ^ 'U' > Traceback (most recent call last): > File "", line

Re: Convert to binary and convert back to strings

2007-02-22 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > For a short string like "Python", using an array is a tiny bit slower, at > the cost of more complex code if you're converting a long string, > using array is faster. If it is a short string, it doesn't make much > difference. I modified your array

Re: Convert to binary and convert back to strings

2007-02-22 Thread Steven D'Aprano
On Thu, 22 Feb 2007 14:29:13 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Arrays don't support XOR any more than strings do. What's the advantage to >> using the array module if you still have to jump through hoops to get it >> to work? > > It's a lot faster. Sometim

Re: Convert to binary and convert back to strings

2007-02-22 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Arrays don't support XOR any more than strings do. What's the advantage to > using the array module if you still have to jump through hoops to get it > to work? It's a lot faster. Sometimes that matters. -- http://mail.python.org/mailman/listinfo/pyt

Re: Convert to binary and convert back to strings

2007-02-22 Thread Steven D'Aprano
On Thu, 22 Feb 2007 08:18:07 +0200, Hendrik van Rooyen wrote: > I would xor each char in it with 'U' as a mild form of obfuscation... I've often wished this would work. >>> 'a' ^ 'U' Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for ^: 'str' an

Re: Convert to binary and convert back to strings

2007-02-22 Thread Steven D'Aprano
On Thu, 22 Feb 2007 11:55:22 +, Jussi Salmela wrote: >> For extra security, you can encode the string with rot13 twice. >> >> >> > > Like this? ;) > > >>> s = "Python" ; u = unicode(s, "ascii") ; u > u'Python' > >>> u.encode('rot13') > 'Clguba' > >>> u.encode('rot13').encode('rot13')

Re: Convert to binary and convert back to strings

2007-02-22 Thread Grant Edwards
On 2007-02-22, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2007-02-22, Ganesan Rajagopal <[EMAIL PROTECTED]> wrote: > >>> I am hoping to have it show up some weird un-readable text. >>> And then of course be able to convert it right back to a >>> string. Is this even possible? >> >> Looks like yo

Re: Convert to binary and convert back to strings

2007-02-22 Thread Neil Cerutti
On 2007-02-22, Jussi Salmela <[EMAIL PROTECTED]> wrote: > Steven D'Aprano kirjoitti: >> On Wed, 21 Feb 2007 16:46:19 -0800, Harlin Seritt wrote: >> WARNING: THIS IS NOT A STRONG ENCRYPTION ALGORITHM. It is just a nuisance for someone that really wants to decrypt the string. But it

Re: Convert to binary and convert back to strings

2007-02-22 Thread Jussi Salmela
Steven D'Aprano kirjoitti: > On Wed, 21 Feb 2007 16:46:19 -0800, Harlin Seritt wrote: > >>> WARNING: THIS IS NOT A STRONG ENCRYPTION ALGORITHM. It is just a >>> nuisance for someone that really wants to decrypt the string. But >>> it might work for your application. >>> >>> -Larry >> Thanks Larry

Re: Convert to binary and convert back to strings

2007-02-22 Thread Steven D'Aprano
On Wed, 21 Feb 2007 16:46:19 -0800, Harlin Seritt wrote: >> WARNING: THIS IS NOT A STRONG ENCRYPTION ALGORITHM. It is just a >> nuisance for someone that really wants to decrypt the string. But >> it might work for your application. >> >> -Larry > > Thanks Larry! I was looking for something more

Re: Convert to binary and convert back to strings

2007-02-22 Thread Paul Rubin
Grant Edwards <[EMAIL PROTECTED]> writes: > > print base64.decodestring(open('sambleb.conf', 'r').read()) > It'll only remain obfuscated for about 30 seconds after even a > mildly curious user looks at the file. You could use the mult127 function, self-inverting like its better known but more easi

Re: Convert to binary and convert back to strings

2007-02-22 Thread Jussi Salmela
Harlin Seritt kirjoitti: > Hi... > > I would like to take a string like 'supercalifragilisticexpialidocius' > and write it to a file in binary forms -- this way a user cannot read > the string in case they were try to open in something like ascii text > editor. I'd also like to be able to read the

Re: Convert to binary and convert back to strings

2007-02-21 Thread Hendrik van Rooyen
"Harlin Seritt" <[EMAIL PROTECTED]> wrote: > Hi... > > I would like to take a string like 'supercalifragilisticexpialidocius' > and write it to a file in binary forms -- this way a user cannot read > the string in case they were try to open in something like ascii text > editor. I'd also like t

Re: Convert to binary and convert back to strings

2007-02-21 Thread Ganesan Rajagopal
> Grant Edwards <[EMAIL PROTECTED]> writes: >> print base64.decodestring(open('sambleb.conf', 'r').read()) > It'll only remain obfuscated for about 30 seconds after even a > mildly curious user looks at the file. It depends on the requirement. If the intention is to just to discourage someon

Re: Convert to binary and convert back to strings

2007-02-21 Thread Grant Edwards
On 2007-02-22, Ganesan Rajagopal <[EMAIL PROTECTED]> wrote: >> I am hoping to have it show up some weird un-readable text. >> And then of course be able to convert it right back to a >> string. Is this even possible? > > Looks like you just want to obfuscate the string. How about > this? > > impor

Re: Convert to binary and convert back to strings

2007-02-21 Thread Ganesan Rajagopal
> "Harlin" == Harlin Seritt <[EMAIL PROTECTED]> writes: > I tried doing this: > text = 'supercalifragilisticexpialidocius' > open('sambleb.conf', 'wb').write(text) > Afterwards, I was able to successfully open the file with a text > editor and it showed: > 'supercalifragilisticexpialidocius

Re: Convert to binary and convert back to strings

2007-02-21 Thread Grant Edwards
On 2007-02-22, Harlin Seritt <[EMAIL PROTECTED]> wrote: >> Try opening your file in the 'wb' mode. > I tried doing this: > > text = 'supercalifragilisticexpialidocius' > > open('sambleb.conf', 'wb').write(text) > > Afterwards, I was able to successfully open the file with a text > editor and it s

Re: Convert to binary and convert back to strings

2007-02-21 Thread [EMAIL PROTECTED]
On Feb 21, 5:50 pm, "Harlin Seritt" <[EMAIL PROTECTED]> wrote: > Hi... > > I would like to take a string like 'supercalifragilisticexpialidocius' > and write it to a file in binary forms -- this way a user cannot read > the string in case they were try to open in something like ascii text > editor.

Re: Convert to binary and convert back to strings

2007-02-21 Thread Harlin Seritt
On Feb 21, 7:12 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > Harlin Seritt wrote: > > Hi... > > > I would like to take a string like 'supercalifragilisticexpialidocius' > > and write it to a file in binary forms -- this way a user cannot read > > the string in case they were try to open in somethin

Re: Convert to binary and convert back to strings

2007-02-21 Thread Harlin Seritt
On Feb 21, 7:02 pm, "Colin J. Williams" <[EMAIL PROTECTED]> wrote: > Harlin Seritt wrote: > > Hi... > > > I would like to take a string like 'supercalifragilisticexpialidocius' > > and write it to a file in binary forms -- this way a user cannot read > > the string in case they were try to open in

Re: Convert to binary and convert back to strings

2007-02-21 Thread Larry Bates
Harlin Seritt wrote: > Hi... > > I would like to take a string like 'supercalifragilisticexpialidocius' > and write it to a file in binary forms -- this way a user cannot read > the string in case they were try to open in something like ascii text > editor. I'd also like to be able to read the bin

Re: Convert to binary and convert back to strings

2007-02-21 Thread Grant Edwards
On 2007-02-21, Harlin Seritt <[EMAIL PROTECTED]> wrote: > I would like to take a string like > 'supercalifragilisticexpialidocius' and write it to a file in > binary forms -- this way a user cannot read the string in case > they were try to open in something like ascii text editor. Why wouldn't t

Re: Convert to binary and convert back to strings

2007-02-21 Thread Colin J. Williams
Harlin Seritt wrote: > Hi... > > I would like to take a string like 'supercalifragilisticexpialidocius' > and write it to a file in binary forms -- this way a user cannot read > the string in case they were try to open in something like ascii text > editor. I'd also like to be able to read the bin