• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Need XOR solution
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need XOR solution


  • Subject: Re: Need XOR solution
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 7 Aug 2002 09:40:05 +0100

"Marc K. Myers" wrote on Tue, 06 Aug 2002 22:22:57 -0400:

>> Date: Tue, 06 Aug 2002 16:33:17 -0400
>> Subject: Re: Need XOR solution
>> From: "Arthur J. Knapp" <email@hidden>
>> To: <email@hidden>
>>
>> > Date: Mon, 05 Aug 2002 18:45:28 -0400
>> > From: "Marc K. Myers" <email@hidden>
>> > Subject: Need XOR solution
>>
>> > Does anyone know of a reasonably fast way to XOR blocks of data
>together?
>
>> > ... I would appreciate it
>> > if someone could point me in the right direction.
>>
>> This is unlikely to be the right direction, but you may find
>> my "manual" XORing to be interesting:
>
>[...snip!...]

>I find it more than interesting; I find it mind-boggling. I've printed
>it out and will attempt to understand it gradually at my leisure. I
>really like the "Bitify" routine which is much simpler than the one I
>was playing with to get bytes as bit patterns.

You could use the brilliant "Fast ASCII" coverter from Arthur's script to
get the number value of each byte, and XOR them together with this:

on Xorify(n1, n2)
set xor to 0
repeat 8 times
if n1 mod 2 is not equal to n2 mod 2 then set xor to xor + 256
set n1 to n1 div 2
set n2 to n2 div 2
set xor to xor div 2
end repeat
-- return xor
end Xorify

This does 8-bit xor's; but it's easily adaptable to handle larger chunks.

...
set addIn to (2 ^ bits)
repeat bits times
if n1 mod 2 is not equal to n2 mod 2 then set xor to xor + addIn
...

NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Setting Frontmost to False
  • Next by Date: Making folders invisible
  • Previous by thread: Re: Need XOR solution
  • Next by thread: Re: Need XOR solution
  • Index(es):
    • Date
    • Thread