The Crypt function is used to encrypt and decrypt data.
Crypt[$] (Key$, Data$)
Key, Data: sexp
Data$ is the buffer holding the data to be encrypted. Key$ specifies the key (max 116 characters = 924 bits) to be used for encryption, which will be used to start the random value generator. Crypt uses a symmetrical coding system, which means that the same key is used to encrypt and to decrypt the data.
OpenW 1
Global secretData As Variant, a$, key$
key$ = "GFA Software"
secretData = "GFA Software GmbH"
Print "Key: " + key$
' Encrypt:
a$ = Crypt(key$, secretData)
Print "Encoded: " + a$
' Decrypt:
secretData = Crypt(key$, a$)
Print "Decode: " + secretData
While InKey = "" : Print AT(1, 5); "Press any key to close." : Wend
CloseW 1
Don't use a key more than once. Don't make it easy to hack. One way to use the same key is to add the length of the data to the key: Crypt(key$+Str(Len(dat$), dat$).
The length of the period of the internal random generator is quite long, so that cracking will take a long time.
Crypt() can be used in many situations. But for really important security issues, you should use a DES or RSA encryption, like PGP. The result of Crypt can be hacked with a brute attack by trying all keys and then scanning the result for readable parts. Better computers also mean better and faster ways to use brute attack possibilities. You can increase the safety by using a checksum function (Crc16/Crc32) after encrypting to validate the encrypted data.
A general weakness with encrypting is the handling of a sequence of bytes with the same value (0-bytes, or spaces). Crypt hides these noticeable sequences, but it is still a weakness. That is why encrypting often is performed on packed data (Pack/UnPack)
Crypt("","") returns a random key of 128 characters.
{Created by Sjouke Hamstra; Last updated: 27/09/2014 by James Gaite}