Re: Need XOR solution
Re: Need XOR solution
- Subject: Re: Need XOR solution
- From: Nigel Garvey <email@hidden>
- Date: Thu, 8 Aug 2002 08:10:39 +0100
"Marc K. Myers" wrote on Wed, 07 Aug 2002 23:05:35 -0400:
>
> Subject: Re: Need XOR solution
>
> Date: Thu, 8 Aug 2002 02:05:43 +0100
>
> From: Nigel Garvey <email@hidden>
>
> To: "AppleScript Users" <email@hidden>
>
>
>
> "Marc K. Myers" wrote on Wed, 07 Aug 2002 16:13:17 -0400:
>
>
>
> >>
>
> >> 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
>
> >
>
> >Could you explain it, briefly, for those
>
> >of us who are less mathematically inclined?
>
>
[...Snip!...]
>
>
> Hope that's clear, not too simple, and/or not too complicated. ;-)
>
>
That's perfectly clear, with just the needed depth of explanation. I
>
understood the comparison of the modulated numbers as the actual
>
extraction of the XORed result, but the addition of 256 when it was true
>
threw me. Your explanation of the use of the extra left-hand bit and
>
how it rotates back to the rightmost position cleared that up for me.
>
You think like an assembly language programmer. Thanks, Nigel.
Good. I could hardly understand it when I read it back myself this
morning. ;-)
If you're feeling really miserly, it occurs to me that you don't actually
*need* the 'xor' variable. As only the bottom eight bits of the two
numbers are used, you could set/not set the ninth bit of one of them. It
would migrate to the right as the original eight bits dropped off the end
and that variable would contain just the XOR result at the end. This
would save having to div 'xor' by 2 and thus save eight 'div's per
character of your text. Probably not much in the overall scheme of
things, but it's nice to know it's possible. :-)
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.