Difference between revisions of "BitRotLeftKey"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
m (Replaced <source> with <syntaxhighlight>; link to creative commons is now https)
 
Line 12: Line 12:
* LSO: 6148 bytes
* LSO: 6148 bytes
* MONO: 2048 bytes
* MONO: 2048 bytes
<source lang="lsl2">key uBitRotLeftKey( string vStrKey, integer vIntRot ){
<syntaxhighlight lang="lsl2">key uBitRotLeftKey( string vStrKey, integer vIntRot ){
vStrKey = (string)llParseString2List( vStrKey, ["-"], [] );
vStrKey = (string)llParseString2List( vStrKey, ["-"], [] );
vStrKey = //-- rotate by characters (half-bytes chunks)
vStrKey = //-- rotate by characters (half-bytes chunks)
Line 42: Line 42:
/*//--                      Anti-License Text                        --//*/
/*//--                      Anti-License Text                        --//*/
/*//    Contributed Freely to the Public Domain without limitation.    //*/
/*//    Contributed Freely to the Public Domain without limitation.    //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  2009 (CC0) [ https://creativecommons.org/publicdomain/zero/1.0/ ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</source><!-- Please do not remove license statement -->
/*//--                                                                --//*/</syntaxhighlight><!-- Please do not remove license statement -->
}}
}}



Latest revision as of 12:41, 9 March 2023

User-Defined Function: key uBitRotLeftKey( string vStrKey, integer vIntRot );

Returns a key that is vStr rotary shifted left vIntRot bits.

  • vStrKey: source key to rotary shift
  • vIntRot: number of bits to shift


Code:

  • LSO: 6148 bytes
  • MONO: 2048 bytes
key uBitRotLeftKey( string vStrKey, integer vIntRot ){
	vStrKey = (string)llParseString2List( vStrKey, ["-"], [] );
	vStrKey = //-- rotate by characters (half-bytes chunks)
	  llGetSubString(
	    vStrKey +
	    llGetSubString( vStrKey,
	                    0xFFFFFFDF, //-- (-33)
	                    (vIntRot >> 2) - 33),
	    0xFFFFFFE0, //-- (-32)
	    0xFFFFFFFF ); //-- (-1)
	 //-- push hex characters on the front end and tack on and extra character for the partial shift wrapping
	vStrKey = "0123456789abcdef" + vStrKey + llGetSubString( vStrKey, 0, 0 );
	vIntRot = 4 - (vIntRot & 3); //-- (4-(vIntRot%4)) get the shift back for a double byte cut
	integer vIdxChr = 16; //-- start past hex characters
	integer vIdxHex;
	do{
		vStrKey +=  //-- pull hex characters from front of string
		  llGetSubString( vStrKey, //-- grab 2 bytes, shift back and AND to get the shifted byte
		                  vIdxHex = ((integer)("0x" + llGetSubString( vStrKey, vIdxChr, ++vIdxChr )) >> vIntRot) & 0xF,
		                  vIdxHex );
	}while (vIdxChr < 48);
	return //-- correct type, grab from the back end, and push proper format
	  (key)(llGetSubString( vStrKey, 0xFFFFFFE0, 0xFFFFFFE7 ) + //-- (-32, -25)
	  "-" + llGetSubString( vStrKey, 0xFFFFFFE8, 0xFFFFFFEB ) + //-- (-24, -21)
	  "-" + llGetSubString( vStrKey, 0xFFFFFFEC, 0xFFFFFFEF ) + //-- (-20, -17)
	  "-" + llGetSubString( vStrKey, 0xFFFFFFF0, 0xFFFFFFF3 ) + //-- (-16, -13)
	  "-" + llGetSubString( vStrKey, 0xFFFFFFF4, 0xFFFFFFFF )); //-- (-12, -1)
}
/*//--                       Anti-License Text                         --//*/
/*//     Contributed Freely to the Public Domain without limitation.     //*/
/*//   2009 (CC0) [ https://creativecommons.org/publicdomain/zero/1.0/ ]   //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                 --//*/

Caveats

  • This function does not check input key validity
  • Expected Range for vIntRot is [0, 127], values outside this range will not give expected results.