User Tools

Site Tools



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 $
 +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 
 +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:
 +BAD:   /​assign uh[<​server>​][<​channel>​][<​nick>​] <​userhost>​
 +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:
 +GOOD:  /assign uh[$encode(<​server>​)][$encode(<​channel>​)] [$encode($<​nick>​)] <​userhost>​
 +Then you can use /FOREACH to iterate over the sub-arrays:
 +/assign array uh[$encode(<​server>​)][$encode(<​channel>​)]
 +/foreach $array x {
 +  echo $array.$x
 +A string that is deterministically based on <​input>​
 +$encode(hello there) ​              ​returns "​GIGFGMGMGPCAHEGIGFHCGF"​
 +$decode(GIGFGMGMGPCAHEGIGFHCGF) ​   returns "hello there"
 +$decode($encode(hello there)) ​     returns "hello there"
 +This function first appeared in ircII-2.2pre8.
encode.txt ยท Last modified: 2016/08/02 22:21 (external edit)