BitRotLeftKey

From Second Life Wiki
Jump to: navigation, search

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) [ http://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.