[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Function: Encode()
Encode() and it's complement, Decode(), perform a simple
Coding method on a character string (or memo). Both are
written in Assembly and are thus very fast. There are no
claims whatsoever on the quality of the Coding method being
used, Although it shouldn't be That easy to break. The coding
used is a simple set of XOR's, circularly with the keyword
passed along, the keyword is never stored in the coded data,
and thus not retrievable in that way.
A good encryption method (like DES or a variant) could also
be used. But that would not be fast enough for your normal
application (scrolling in dbEdit (sorry, TBrowse) screens
would then be slow, for instance). Encode() and Decode() are
simple enough to be nearly instanteneous, yet complicated
enough for someone to crack it.
Encode() returns a string of the same length, it could thus
be used on normal database fields to encode your .DBF files.
Encode() does not store the key used to code the string, you
Need to submit that same key to Decode(). Supplying another
key will make Decode() return garbage (it returns an string
encoded twice, in fact).
Encode() and Decode() can be used on .DBT files if some care
is taken. If your Memo-Fields do not contain any high chars
(ie. above Chr(128)) and nor does your Key, Then the
field may be encoded, as Encode() will generate High chars.
Otherwise, you should take care that the encoded memo does
not contain any Chr(26) (Ctrl-Z, EOF) by using StrTran().
Syntax: Encode(<cStr>,<cKey>) --> cCodedStr
Arguments: <cStr> is the string to encode. Memos and strings
up to any length will be encoded. <cKey> is the keyword
to be used to encode, the longer the key, the more difficult
it will be to crack (And long keys do not have any effect
on the speed of Coding/Decoding).
Returns: a String, encoded using <cKey>.
Usage: /* Simple Encoding... */
x := Encode(x,'key')
/* A little subtler.. */
x := Encode(x,'Pepijn Smits Encoding Key')
/* Even more subtler.. */
x := Encode(x,Encode(Reverse('Pepijn Smits Encoding'),'key'))
If you want to Encode numbers/dates, you should store them as
their binary (string) equivalent.
// Integers can be stored as 2 chars, or 4 chars. Then:
x := Encode(i2bin(Number),key) // 16 bits numbers.
// or:
x := Encode(l2bin(Number),key) // 32 bit numbers..
// or:
x := Encode(d2bin(Float),key) // Real numbers.
// then retrieve as follows:
Number := bin2i(decode(x,key))
Float := bin2d(decode(x,key))
// dates can be stored as 8 bytes:
x := Encode(DtoS(DateVar),key)
// or 2 bytes:
x := Encode(PackDate(DateVar),key)
// restore dates as follows:
DataVar := StoD(decode(x,key))
// or:
DateVar := UnPackDate(Decode(x,key))
Note that d2bin(), bin2d(), PackDate(), UnPackDate() and
StoD() are all Expand library functions.
See Also:
PackStr()
Decode()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson