Site Tools


encode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

encode [2016/08/02 22:21] (current)
Line 1: Line 1:
 +# $EPIC: encode.txt,v 1.4 2009/06/01 00:47:41 jnelson Exp $
 +======Synopsis:======
 +$__encode__(<text>)
 +
 +======Technical:======
 +If the <text> argument is omitted the empty string is returned.
 +
 +The output of this function is a transformation of <text> that has 
 +the following characteristics AND ONLY the following characteristics:
 +^ Characteristic ^ Example ^
 +| It is unique | encode(X) != encode(Y) for all X != Y |
 +| It is case sensitive: | encode(foo) != encode(FOO) |
 +| It is reversable: | decode($encode(foo)) == [foo] |
 +| It creates an lval: | @ encode(foo) = [bar] |
 +
 +This particular implementation breaks each octet in <text> into two four bit 
 +nybbles and adds the nybble to 0x41.  The return value is therefore twice the 
 +length of the input <text> THIS IS SUBJECT TO CHANGE IN THE FUTURE.
 +
 +Hardcoding $encode()d values into your script IS A BAD THING.  Please be 
 +aware that $encode() may change in the future and your script will break 
 +and IT WON'T BE MY FAULT.
 +
 +======Practical:======
 +It is common practice to use associative arrays to store information about
 +servers, channels, and nicknames.  Consider if you wanted to be able to 
 +store the userhost of every user on every channel you are on.  You might
 +want to organize it like:
 +
 +<file>
 +BAD:   /assign uh[<server>][<channel>][<nick>] <userhost>
 +</file>
 +
 +Unfortunately, <server>, <channel>, and <nick> might contain characters 
 +that are not valid characters in a variable name.  If you tried to do it,
 +you would get the error "ASSIGN names may not contain ...."
 +
 +The $encode() function converts any arbitrary string of text into a
 +string that can be used as part of a variable name:
 +
 +<file>
 +GOOD:  /assign uh[$encode(<server>)][$encode(<channel>)] [$encode($<nick>)] <userhost>
 +</file>
 +
 +Then you can use /FOREACH to iterate over the sub-arrays:
 +
 +<file>
 +/assign array uh[$encode(<server>)][$encode(<channel>)]
 +/foreach $array x {
 +  echo $array.$x
 +}
 +</file>
 +
 +======Returns:======
 +A string that is deterministically based on <input>
 +
 +======Examples:======
 +<file>
 +$encode(hello there)               returns "GIGFGMGMGPCAHEGIGFHCGF"
 +$decode(GIGFGMGMGPCAHEGIGFHCGF)    returns "hello there"
 +$decode($encode(hello there))      returns "hello there"
 +</file>
 +
 +======History======
 +This function first appeared in ircII-2.2pre8.
  
encode.txt ยท Last modified: 2016/08/02 22:21 (external edit)