Difference between revisions of "Key compression"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
'''Compress Keys of all sorts''' | '''Compress Keys of all sorts''' | ||
<lsl> | <lsl> | ||
string | string strFullCompression = "0123456789abcdefghijklmnopqrstuvwxyz!\"#$%&'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅ"; | ||
string compressKey(key id){ | string compressKey(key id){ | ||
string str = (string)llParseString2List((string)id,["-"],[]); | string str = (string)llParseString2List((string)id,["-"],[]); | ||
Line 12: | Line 9: | ||
integer len = llStringLength(str); | integer len = llStringLength(str); | ||
while(i < len){ | while(i < len){ | ||
integer val = llSubStringIndex( | integer val = llSubStringIndex(strFullCompression,(llGetSubString(str,i,i))); | ||
++i; | ++i; | ||
integer val2 = llSubStringIndex( | integer val2 = llSubStringIndex(strFullCompression,(llGetSubString(str,i,i))); | ||
val *= 16; | |||
val += val2; | |||
output += llGetSubString(strFullCompression,val,val); | |||
++i; | ++i; | ||
} | } | ||
Line 35: | Line 26: | ||
string output; | string output; | ||
while(i < len){ | while(i < len){ | ||
integer indx = llSubStringIndex( | integer indx = llSubStringIndex(strFullCompression,llGetSubString(compressed,i,i)); | ||
integer val1 = (integer)indx / 16; | |||
integer val2 = indx % 16; | |||
output += llGetSubString(strFullCompression,val1,val1) + llGetSubString(strFullCompression,val2,val2); | |||
++i; | ++i; | ||
} | } | ||
Line 49: | Line 36: | ||
} | } | ||
</lsl> | </lsl> | ||
Revision as of 17:46, 21 February 2008
Compress Keys of all sorts
<lsl> string strFullCompression = "0123456789abcdefghijklmnopqrstuvwxyz!\"#$%&'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅ"; string compressKey(key id){
string str = (string)llParseString2List((string)id,["-"],[]); integer i; string output; integer len = llStringLength(str); while(i < len){ integer val = llSubStringIndex(strFullCompression,(llGetSubString(str,i,i))); ++i; integer val2 = llSubStringIndex(strFullCompression,(llGetSubString(str,i,i))); val *= 16; val += val2; output += llGetSubString(strFullCompression,val,val); ++i; } return output;
}
string decompressKey(string compressed){
integer i; integer len = llStringLength(compressed); string output; while(i < len){ integer indx = llSubStringIndex(strFullCompression,llGetSubString(compressed,i,i)); integer val1 = (integer)indx / 16; integer val2 = indx % 16; output += llGetSubString(strFullCompression,val1,val1) + llGetSubString(strFullCompression,val2,val2); ++i; } return llGetSubString(llInsertString(llInsertString(llInsertString(llInsertString(llInsertString(llToLower(output),12,""),8,"-"),13,"-"),18,"-"),23,"-"),0,35);
} </lsl>