Difference between revisions of "Talk:Key Compression"

From Second Life Wiki
Jump to navigation Jump to search
(New page: Recommending the following for base64 example for compatibility: <lsl>string keyToBase64(string s) { s = llDumpList2String(llParseString2List(s, ["-"], []), ""); return llGetS...)
 
m (<lsl> to <source>)
Line 1: Line 1:
Recommending the following for base64 example for compatibility:
Recommending the following for base64 example for compatibility:


<lsl>string keyToBase64(string s) {
<source lang="lsl2">string keyToBase64(string s) {
   s = llDumpList2String(llParseString2List(s, ["-"], []), "");
   s = llDumpList2String(llParseString2List(s, ["-"], []), "");
   return
   return
Line 41: Line 41:
       integer2hex(llBase64ToInteger(llGetSubString(s,16,19))) +
       integer2hex(llBase64ToInteger(llGetSubString(s,16,19))) +
       integer2hex(llBase64ToInteger(llGetSubString(s,20,21)+"AA")));
       integer2hex(llBase64ToInteger(llGetSubString(s,20,21)+"AA")));
}</lsl>
}</source lang="lsl2">

Revision as of 03:09, 5 February 2015

Recommending the following for base64 example for compatibility:

<source lang="lsl2">string keyToBase64(string s) {

  s = llDumpList2String(llParseString2List(s, ["-"], []), "");
  return
     llGetSubString(llIntegerToBase64((integer)("0x"+llGetSubString(s,0,5))<<8),0,3) +
     llGetSubString(llIntegerToBase64((integer)("0x"+llGetSubString(s,6,11))<<8),0,3) +
     llGetSubString(llIntegerToBase64((integer)("0x"+llGetSubString(s,12,17))<<8),0,3) +
     llGetSubString(llIntegerToBase64((integer)("0x"+llGetSubString(s,18,23))<<8),0,3) +
     llGetSubString(llIntegerToBase64((integer)("0x"+llGetSubString(s,24,29))<<8),0,3) +
     llGetSubString(llIntegerToBase64((integer)("0x"+llGetSubString(s,30,31))<<24),0,1);

}

string integer2hex(integer in) {

  string s = "0123456789abcdef";
  string ret = "";
  integer i;
  in = in >> 8;
  for (i = 0; i < 6; i++) {
     ret = llGetSubString(s, in & 0xF, in & 0xF) + ret;
     in = in >> 4;
  }
  return ret;

}

string pad_dash(string s) {

  return
     llGetSubString(s, 0, 7) + "-" +
     llGetSubString(s, 8,11) + "-" +
     llGetSubString(s,12,15) + "-" +
     llGetSubString(s,16,19) + "-" +
     llGetSubString(s,20,31);

}

key base64ToKey(string s) {

  return (key) pad_dash(
     integer2hex(llBase64ToInteger(llGetSubString(s,0,3))) +
     integer2hex(llBase64ToInteger(llGetSubString(s,4,7))) +
     integer2hex(llBase64ToInteger(llGetSubString(s,8,11))) +
     integer2hex(llBase64ToInteger(llGetSubString(s,12,15))) +
     integer2hex(llBase64ToInteger(llGetSubString(s,16,19))) +
     integer2hex(llBase64ToInteger(llGetSubString(s,20,21)+"AA")));

}</source lang="lsl2">