Re: Need XOR solution
Re: Need XOR solution
- Subject: Re: Need XOR solution
- From: has <email@hidden>
- Date: Tue, 6 Aug 2002 01:29:17 +0100
Marc K. Myers wrote:
>
Does anyone know of a reasonably fast way to XOR blocks of data together?
>
>
I'm working on an AppleScript implementation of a one-time pad
>
crytography system. Right now I'm XORing the plaintext against the key
>
using the "Bits & Bytes" osax, which requires me to convert each byte
>
from each file to its ASCII number equivalent, run the "bitwiseXOR"
>
command on it, and then convert the result to its ASCII character
>
equivalent.
Ow, three osax calls for every character... that's gotta hurt speedwise.
>
This kind of logical data manipulation is so basic that
>
there's *got* to be a better approach than that! I would appreciate it
>
if someone could point me in the right direction.
Any good language that supports bitwise operations, I should think.:)
Joking aside, what you could do is build yourself a 256x256 lookup table
[1] containing all possible results at compile-time. You then use a
TID-based 'ascii number' routine to get the x/y coords for a given solution
based upon the source and key characters.
To build your tables at compile-time, you can use stuff like the following:
on _buildASCIILookupString()
set str to ""
repeat with x from 0 to 255
set str to str & (ASCII character x)
end repeat
return str
end _buildASCIILookupString
property asciiLookupString : _buildASCIILookupString()
If you want to rake around the ghastly code in my converterLib, you can see
how it does TID-based ascii<->integer conversions and stuff as well, though
for a routine like this you'll probably want to optimise the heck out of
everything and inline/minimise as much of the code as possible.
You can also improve your compile-time by optimising the main
table-building code if you wish, again by using TID-based ascii<->integer
conversions. You may also prefer to use a vanilla bitwiseXOR function, e.g.
you can find one in the ESG MathLib library <
http://www.esglabs.com/> (this
may or may not be faster than the osax - you'd have to test this - and it
will make it easier to (re)compile the library on a machine without the
Bits&Bytes osax, should you need to do so.)
If you need any further help, just mail me. HTH
has
[1] For speed and memory reasons, I recommend you use a single large string
rather than lists and use 'get lookupString's item (x + (y * 256))' to
retrieve values from it.
--
(My email address has changed from <email@hidden> to
<email@hidden>. Please update your address books accordingly.)
_______________________________________________
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.