Re: [Tutor] string to binary and back... Python 3

2012-07-20 Thread eryksun
On Fri, Jul 20, 2012 at 3:16 AM, Alan Gauld wrote: > On 20/07/12 06:48, wolfrage8...@gmail.com wrote: > > Using the format method it would look like: > > newhexdata = bytes("{0:x}".format(numdata), "ascii") binascii.unhexlify needs an even number of hexadecimal digits (two per byte). So you need

Re: [Tutor] string to binary and back... Python 3

2012-07-20 Thread Alan Gauld
On 20/07/12 06:48, wolfrage8...@gmail.com wrote: Thanks I will give this a try. Can you explian a little further for me what exactly this: newhexdata = bytes("%x" % numdata, "ascii") line is doing? I don't quite understand the use of the "%x" % on numdata. It is standard string formatting in

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
You forgot to include the list. So I'm forwarding it now, with new remarks. On 07/20/2012 01:47 AM, wolfrage8...@gmail.com wrote: > On Fri, Jul 20, 2012 at 12:33 AM, Dave Angel wrote: > >> On 07/19/2012 05:55 PM, Prasad, Ramit wrote: I am not sure how to answer that question because all fi

[Tutor] string to binary and back... Python 3

2012-07-19 Thread wolfrage8...@gmail.com
On Fri, Jul 20, 2012 at 12:33 AM, Dave Angel wrote: > On 07/19/2012 05:55 PM, Prasad, Ramit wrote: > >> I am not sure how to answer that question because all files are binary, > >> but the files that I will parse have an encoding that allows them to be > >> read in a non-binary output. But my p

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 5:32 PM, Jordan wrote: > > I am not sure how to answer that question because all files are binary, > but the files that I will parse have an encoding that allows them to be > read in a non-binary output. But my program will not use the in a > non-binary way, that is why I p

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/19/2012 05:55 PM, Prasad, Ramit wrote: >> I am not sure how to answer that question because all files are binary, >> but the files that I will parse have an encoding that allows them to be >> read in a non-binary output. But my program will not use the in a >> non-binary way, that is why I pl

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> I am not sure how to answer that question because all files are binary, > but the files that I will parse have an encoding that allows them to be > read in a non-binary output. But my program will not use the in a > non-binary way, that is why I plan to open them with the 'b' mode to > open them

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 10:48 PM, Prasad, Ramit wrote: OK. I am using one time pads to XOR data, but the one time pads (keys) are very large numbers, converting them to binary increases their size exponentially, which allows me to get more XORing done out of a single >>> You want

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> > bin_data = [ bin(ord(char)).split('b')[1].zfill(8) for char in data ] > > bin_string = ''.join(bin_data) > > bin_list = [ chr( int(char, 2) ) for char in bin_data ] > Thank you exactly what I was looking for! > > > > I am not really sure what you are getting at with XOR and one time > > padding

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/18/2012 05:07 PM, Jordan wrote: > OK so I have been trying for a couple days now and I am throwing in the > towel, Python 3 wins this one. I should have paid more attention to this the first time. Clearly you don't want help. -- DaveA ___ Tut

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> >> > >> > >> OK. I am using one time pads to XOR data, but the one time pads (keys) > >> are very large numbers, converting them to binary increases their size > >> exponentially, which allows me to get more XORing done out of a single > > You want to explain this impossibility of increasing siz

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
Sorry, I am not sure why Thunderbird is stripping the spaces, may have something to do with a plug-in that I have installed, I will have to look into it. On 07/19/2012 10:41 PM, Prasad, Ramit wrote: > Sure, this makes perfect sense to me :) (adding indent) > > for char in data: > bin_data += b

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 10:04 PM, eryksun wrote: > On Thu, Jul 19, 2012 at 3:08 PM, Jordan wrote: > I'm not an expert with cryptography, but here's a simple XOR example: from itertools import cycle text = b'Mary had a little lamb.' key = b'1234' cypher = bytes(x^y for x,y in zip(text,

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> > bin(integer).split('b')[1].zfill( multiple_of_eight ) > OK so using this: Hopefully my copy paste works this time. > > bin_data = '' > > for char in data: > > bin_data += bin(ord(char)).split('b')[1].zfill(8) > > print(bin_data) > > bin_list = [bin_data[x:x + 2] for x in range(0, len(bin_d

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 09:53 PM, Dave Angel wrote: > On 07/19/2012 03:19 PM, Jordan wrote: >> >> >> OK. I am using one time pads to XOR data, but the one time pads (keys) >> are very large numbers, converting them to binary increases their size >> exponentially, which allows me to get more XORing done ou

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 3:08 PM, Jordan wrote: > > size = 8 * max(len(b3), len(b4)) > format(r, "0%db" % size) >> '0011001100110011' > Is this output the output for size rather than the two variables joined > together? Using "format" is useful if you need the string to be

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 09:23 PM, Prasad, Ramit wrote: >> A question I have for the group before I respond is a option that I saw >> that I had earlier was to ord() each element of a string and then bin() >> that number. But since bin() produces a string I could not figure out >> the correct way to attach

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/19/2012 03:19 PM, Jordan wrote: > > > OK. I am using one time pads to XOR data, but the one time pads (keys) > are very large numbers, converting them to binary increases their size > exponentially, which allows me to get more XORing done out of a single You want to explain this impossibili

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> A question I have for the group before I respond is a option that I saw > that I had earlier was to ord() each element of a string and then bin() > that number. But since bin() produces a string I could not figure out > the correct way to attach two bin() outputs back together again due to > the

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 08:53 PM, Prasad, Ramit wrote: >>> I think your basic problem is too much conversion because you do not >>> understand the types. A string is represented by a series of bytes >>> which are binary numbers. Do you understand the concept behind ASCII? >>> Each letter has a numeric repr

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
A question I have for the group before I respond is a option that I saw that I had earlier was to ord() each element of a string and then bin() that number. But since bin() produces a string I could not figure out the correct way to attach two bin() outputs back together again due to the leading 'b

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
My response is down lower, thank you Wayne. On 07/19/2012 12:52 PM, Wayne Werner wrote: > I'll preface my response by saying that I know/understand fairly > little about > it, but since I've recently been smacked by this same issue when > converting > stuff to Python3, I'll see if I can explain it

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> > I think your basic problem is too much conversion because you do not > > understand the types. A string is represented by a series of bytes > > which are binary numbers. Do you understand the concept behind ASCII? > > Each letter has a numeric representation that are sequential. So the > > stri

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 12:46 PM, Dave Angel wrote: > On 07/19/2012 01:41 AM, wolfrage8...@gmail.com wrote: >> On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: > That was just the first line that was not indented. If I thought you > had a one-line while loop, I certainly would have just indented it.

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 08:14 AM, Mark Lawrence wrote: > On 19/07/2012 06:41, wolfrage8...@gmail.com wrote: >> On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: >> > > Really? Are you using a forked version of Python that doesn't need > indentation after a while loop, or are you speaking with a forked

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 12:15 AM, Prasad, Ramit wrote: > I think your basic problem is too much conversion because you do not > understand the types. A string is represented by a series of bytes > which are binary numbers. Do you understand the concept behind ASCII? > Each letter has a numeric representat

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 1:41 AM, wolfrage8...@gmail.com wrote: > > I was comparing them but I think I understand how to compare them well, now > I want to convert them both to binary so that I can XOR them together. Thank > you for your time and help Dave, now I need to reply to Ramit. A bytes ob

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Wayne Werner
I'll preface my response by saying that I know/understand fairly little about it, but since I've recently been smacked by this same issue when converting stuff to Python3, I'll see if I can explain it in a way that makes sense. On Wed, 18 Jul 2012, Jordan wrote: OK so I have been trying for a c

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/19/2012 01:41 AM, wolfrage8...@gmail.com wrote: > On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: > >> >> I don't get the same error you did. I get: >> >> File "jordan.py", line 13 >> test_int = int(str(test_int) + str(int.from_bytes(os.urandom(1), >> 'big'))) >>^ >> >

Re: [Tutor] string to binary and back... Python 3

2012-07-18 Thread Mark Lawrence
On 19/07/2012 06:41, wolfrage8...@gmail.com wrote: On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: On 07/18/2012 05:07 PM, Jordan wrote: OK so I have been trying for a couple days now and I am throwing in the towel, Python 3 wins this one. I want to convert a string to binary and back a

Re: [Tutor] string to binary and back... Python 3

2012-07-18 Thread wolfrage8...@gmail.com
On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: > On 07/18/2012 05:07 PM, Jordan wrote: > > OK so I have been trying for a couple days now and I am throwing in the > > towel, Python 3 wins this one. > > I want to convert a string to binary and back again like in this > > question: Stack Over

Re: [Tutor] string to binary and back... Python 3

2012-07-18 Thread Steven D'Aprano
On Wed, Jul 18, 2012 at 10:22:43PM +, Prasad, Ramit wrote: > I forgot to say, that once you have the integer equivalents, > you can then convert that easily to binary using bin. > I used ast.literal_eval to convert from binary string > (as returned from bin) to number, but there might be bet

Re: [Tutor] string to binary and back... Python 3

2012-07-18 Thread Prasad, Ramit
> > I think your basic problem is too much conversion because you do not > understand the types. A string is represented by a series of bytes > which are binary numbers. Do you understand the concept behind ASCII? > Each letter has a numeric representation that are sequential. > So the string 'abc

Re: [Tutor] string to binary and back... Python 3

2012-07-18 Thread Dave Angel
On 07/18/2012 05:07 PM, Jordan wrote: > OK so I have been trying for a couple days now and I am throwing in the > towel, Python 3 wins this one. > I want to convert a string to binary and back again like in this > question: Stack Overflow: Convert Binary to ASCII and vice versa > (Python) >

Re: [Tutor] string to binary and back... Python 3

2012-07-18 Thread Prasad, Ramit
> OK so I have been trying for a couple days now and I am throwing in the > towel, Python 3 wins this one. > I want to convert a string to binary and back again like in this > question: Stack Overflow: Convert Binary to ASCII and vice versa > (Python) >

[Tutor] string to binary and back... Python 3

2012-07-18 Thread Jordan
OK so I have been trying for a couple days now and I am throwing in the towel, Python 3 wins this one. I want to convert a string to binary and back again like in this question: Stack Overflow: Convert Binary to ASCII and vice versa (Python)