REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: encloak

encloak  data  key  /with

Scrambles a binary string based on a key. (Modifies)


data [binary!] - Binary to scramble

key [string! binary! integer!] - Encryption key or pass phrase


/with - Use a string! key as-is (do not generate hash)

See also:



encloak is a low strength encryption method that can be useful for hiding passwords and other such values. It is not a replacement for AES or Blowfish, but works for noncritical data.

Do not use it for top secret information!

To cloak a binary string, provide the binary string and a cloaking key to the encloak function:

bin: encloak #{54686973206973206120737472696E67} "a-key"

To cloak a string of characters, convert it using to-binary :

bin: encloak to-binary "This is a string" "a-key"

The result is an encrypted binary value which can be decloaked with the line:

print decloak bin "a-key"

The stronger your key, the better the encryption. For important data use a much longer key that is harder to guess. Also, do not forget your key, or it may be difficult or impossible to recover your data.

Now you have a simple way to save out a hidden string, such as a password:

key: ask "Cloak key? (do not forget it) "
data: to-binary "string to hide"
save %data encloak data key

To read the data and decloak it:

key: ask "Cloak key? "
data: load %data
data: to-string decloak data key

Of course you can cloak any kind of data using these functions, even non-character data such as programs, images, sounds, etc. In those cases you do not need the to-binary conversion shown above.

Note that by default, the cloak functions will hash your key strings into 160 bit SHA1 secure cryptographic hashes. If you have created your own hash key (of any length), you use the /with refinement to provide it.

  TOC < Back Next > - WIP Wiki Feedback Admin