xor on strings

Darrell dgallion1 at yahoo.com
Mon Feb 11 00:28:56 EST 2002


Not sure what you want so here's what I have.

You can zero pad the hex digits instead of using hex()
>>> '%0.2x'%12
'0c'

>>> s1='ab'
>>> s2='abccc'
>>> map(max,zip(min(s1,s2).ljust(len(max(s1,s2))),max(s1,s2)))
['a', 'b', 'c', 'c', 'c']

--Darrell

dsavitsk wrote:

> the truncate part is the problem.  I am building VB Hex strings to send to
> a
> VB server.  so
> 
>>>> red = hex(56)[2:4]
>>>> green = hex(156)[2:4]
>>>> blue = hex(12)[2:4]
>>>> thestring = '&H' + blue + green + red
> 
> but here, since the blue string is only 1 character it throws the rest
> off.
> 
> -d
> 
> "Joshua Muskovitz" <joshm at taconic.net> wrote in message
> news:3c674cbd_2 at corp.newsgroups.com...
>> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
>> >>> ''.join(map(max,zip('00','AA')))
>> 'AA'
>> >>> ''.join(map(max,zip('00','A')))
>> 'A'
>> >>> ''.join(map(max,zip('00','')))
>> ''
>>
>> Damn, I thought I had it.  :-)  Is there an variant of zip which doesn't
>> truncate?  BTW, this does work, provided that the input strings are the
> same
>> length, and even allows for more than two strings!
>>
>> >>> s = ['abte','scrt','sdfw','cxvs']
>> >>> ''.join(map(max,zip(*s)))
>> 'sxvw'
>>
>> --
>> # Joshua Muskovitz
>> # joshm at taconic.net
>> def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"])
>> lyyrs('Hire me!  I need the work!')
>>
>>
>>
>>
>> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
>> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
>> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----




More information about the Python-list mailing list