baseConvert() & 32-bit ops (was Best array population & access optimization)
Dar Scott
dsc at swcp.com
Sat Jun 21 17:21:28 EDT 2003
On Saturday, June 21, 2003, at 03:12 PM, Graham wrote:
> Not wanting to stop the flow, but for the benefit of the rest of us,
> what is this topic actually about? I didn't realise that a discussion
> in this list could go entirely over my head... I feel really stupid.
Mostly about primitives that those writing encryption software would be
interested in. (There are more general uses.) In particular, Mark is
working with Blowfish that uses 32-bit half blocks.
Even thought Revolution is 8-byte (double) floating point in its
arithmetic, this is suitable for representing an (imaginary, perhaps)
32-bit number. There are some built-in Transcript functions that work
with this 32-bit view.
These include bitAnd, bitOr, bitNot and bitXor. These perform bit-wise
logical operations on numbers.
The baseConvert() uses a 32-bit number as an intermediate value, it
seems.
Missing are the shift and rotate commands/functions. Fortunately, Mark
doesn't really need those. Those can easily be written, but they will
be slow.
Also important is initialization, traditionally from hex tables. This
can be done with baseConvert, binaryEncode and binaryDecode.
Another common task is the mapping of strings to and from the block
list/array used by some algorithms. I think binaryEncode and
binaryDecode are helpful here.
Other Revolution commands/functions such as compress and md5Digest are
also handy. I wouldn't use the built-in random for this. I don't
think Mark needs random for what he wants.
Algorithms often use arrays or matrices called boxes in this jargon.
In Blowfish, mark is looking at ways to represent those. He might
represent all S -boxes and P-boxes as a single array (handy as a single
unit), or he might break the S-boxes into 4 arrays and use a separate
18 variables for the P boxes (great for speed). That is part of the
problem in optimization and maximizing utility.
These same problems also come up in other areas such as control I/O and
reading & writing some kinds of binary files.
Dar Scott
More information about the use-livecode
mailing list