Difference between revisions of "User:Kireji Haiku/SIMchat headset"

From Second Life Wiki
Jump to navigation Jump to search
m
m (<lsl> tag to <source>)
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Help |Wiki=*}}
{{LSL Header}}
{{LSL Header}}
<span id="top"></span>
<div style="float:right;">__TOC__</div>
<div style="float:right;">__TOC__</div>
=SIMchat headset=
<div id="box">
<div id="box">
==SCRIPT:==
<div style="padding: 0.5em;">
<div style="padding: 0.5em;">


= SIMchat headset by [[User:Kireji Haiku|Kireji]] =


This script is being provided "as is". It's been thoroughly tested in May 2010.
== General information: ==


If you want to use it, you should drop it into a <font color="red">childprim</font> of a linkset. This setup will give you the possibilty to forward your chat on a certain channel <font color="red">within</font> the whole region your are in and <font color="red">encrypt</font> it. Just make sure anybody you want to talk to has the same variables as you do.
If you want to use it, you should drop it into a <font color="red">childprim</font> of a linkset.
This setup will give you the possibilty to forward your chat on a certain channel <font color="red">within</font> the whole region your are in and <font color="red">encrypt</font> it.
Just make sure anybody you want to talk to has the same variables as you do.


You can turn off the SIMchat function (if you are being spammed on that channel...you could of course change the channel, too), get a SLURL to your current location, get the current count of avatars within the region or get a quick reminder of the currently-used-channel and a howto <font color="red">by touching the childprim</font> containing this script.
[[File:SIMchat_Headset.jpg|thumb|700px|center|This is what it could look like. There's no particle system in the script, I just added it for demonstration purposes.]]


[[File:SIMchat_Headset_grey.jpg|thumb|700px|center|Yellow marker shows the root prim (parent), red marker shows the invisible linked prim (child) containing the script.]]


[[File:SIMchat_Headset.jpg|thumb|700px|center|This is what it could look like. Shown in the picture is the active state of the headset with blinking particle light.]]
[[#top|Back to top!]]


[[File:SIMchat_Headset_grey.jpg|thumb|700px|center|Yellow marker shows the main prim, red marker shows the invisible childprim containing the script.]]
== Script: ==


</div></div>
<source lang="lsl2">
// This script includes the XTEA-LSL-Implementation by:
//  - Morse Dillon
//  - Strife Onizuka
//  - Dedric Mauriac
//  - JB Kraft
//  http://wiki.secondlife.com/wiki/XTEA_Strong_Encryption_Implementation


//  Setup:
//  1. Make sure the object in which you want to use this script has more than one prim.
//  2. Make sure the object is modifiable by you.
//  3. This script must go into a childprim of your object, it doesn't matter into which one.
//  4. After you have copied the script into your object, make sure everyone you want to talk to has the same
//    settings for KEY1, KEY2, KEY3, KEY4 and COMM_CHANNEL. You can use any valid, positive (!) integer number
//    for COMM_CHANNEL excluding PUBLIC_CHANNEL (which is 0) and DEBUG_CHANNEL (which is 2147483647). Do not use
//    a negative channel!
//  5. When chatting, please type in local chat and add your channel. Example: If your COMM_CHANNEL was 9 then you'd type: '/9 hello'
//  6. The code is written for an avatar attachment (usually a headset / HUD) and will run in no-script areas.


[http://wiki.secondlife.com/wiki/User:Kireji_Haiku/SIMchat_headset Go to top!]
<lsl>
integer COMM_CHANNEL = 9;
string  ProtocolSignature = "ENC";//your signature
integer KEY1        = 11111111;
float  ProtocolVersion = 0.3; // can range from 0.0 to 255.255
integer KEY2        = 22222222;
string Password = "P@ssw0rd";//your password
integer KEY3        = 33333333;
integer communicationsChannel = 9;//the channel you use for communication
integer KEY4        = 44444444;
integer mChannel = 8989;//channel for dialog-menu
string strHex = "0123456789ABCDEF";//hex-password
// If you're not sure what you're doing,
// do NOT change anything below!
key    ownerKey;
string  ownerName;
integer CYCLES    = 6;
   
list    cypherkey;
integer delta    = 0x9E3779B9;
integer ord(string chr)
{
    if (llStringLength(chr) != 1)
    {
        return ERR_GENERIC;
    }
    if (chr == " ")
    {
        return 32;
    }
    string ASCII = "             \n                    !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    return llSubStringIndex(ASCII, chr);
}
string chr(integer i)
{
    i %= 127;


    string ASCII = "            \n                    !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    return llGetSubString(ASCII, i, i);
}
string DWord2Hex(integer m)
{
    string  result;
    integer index;
    string  characters = "0123456789ABCDEF"; 
    integer i;
    for (; i < 8; i++)
    {
        index  = (m >> (i * 4)) & 0xF;
        result = llInsertString(result, 0, llGetSubString(characters, index, index));
    }
    return result;
}
integer Hex2DWord(string m)
{
    integer result;
    string digit;
    integer value;
    integer index;
    string characters = "0123456789ABCDEF";
    integer i;
    for (; i < 8; i++)
    {
        index = 8 - (i + 1);
        digit = llGetSubString(m,index,index);
        value = llSubStringIndex(characters, digit);
        result = result | value << (i * 4);
    }
    return result;
}
string Encrypt(string cleartext)
{
    integer cyphertext_numeric;
    integer dword1;
    integer dword2;
    list    cypherblock;
    string  cyphertext;


    while(llStringLength(cleartext) & 0x7)
    {
        cleartext += " ";
    }


//##############################################################################
    integer character;
//do not change anything below if you are not 100% sure about what you are doing
    integer stringlength = llStringLength(cleartext);
//##############################################################################


    integer i;
    while (i < stringlength)
    {
        dword1 =  ord(llGetSubString(cleartext,i,i));
        i++;
        dword1 =  dword1 | (ord(llGetSubString(cleartext,i,i)) << 8);
        i++;
        dword1 =  dword1 | (ord(llGetSubString(cleartext,i,i)) << 16);
        i++;
        dword1 =  dword1 | (ord(llGetSubString(cleartext,i,i)) << 24);
        i++;


string Header;
        dword2 = ord(llGetSubString(cleartext,i,i));
integer Debug = TRUE;
        i++;
integer listener;
        dword2 = dword2 | ord(llGetSubString(cleartext,i,i)) << 8;
integer gListenID = -1;
        i++;
integer X;
        dword2 =  dword2 | ord(llGetSubString(cleartext,i,i)) << 16;
integer Y;
        i++;
integer Z;
        dword2 = dword2 | ord(llGetSubString(cleartext,i,i)) << 24;
key    user;
        i++;
list    mainmenu = ["RegionCount","SLURL","SIMchatOFF","Chat info","Chat howto"];
string  Name;
string  SLURL;
string  menu_info_1 = "


    This popup shows up because you touched your SIMchat headset.
        cypherblock = TEAEncrypt(dword1,dword2,cypherkey);


         ";
         cyphertext = cyphertext + DWord2Hex(llList2Integer(cypherblock,0)) + DWord2Hex(llList2Integer(cypherblock,1));
string  menu_info_2 = "Choose one of the following.";
string  prim_name;
string  prim_desc;
vector  Where;
string  CONTROLLER_ID = "A";
integer AUTO_START = TRUE;
list    particle_parameters=[];
list    target_parameters=[];


string error(string message)
        dword1      = 0;
        dword2      = 0;
        cypherblock = [];
    }
 
    return cyphertext;
string Decrypt(string cyphertext)
{
{
     if(Debug) llSay(DEBUG_CHANNEL, message);
     integer dword1;
     return "";
    integer dword2;
    list    clearblock;
    string  cleartext;
    string  hexvalue1;
    string  hexvalue2;
 
    integer i;
    while (i < llStringLength(cyphertext))
    {
        hexvalue1 += llGetSubString(cyphertext,i,i + 7);
        i = i + 8;
 
        hexvalue2 += llGetSubString(cyphertext,i,i + 7);
        i = i + 8;
 
        dword1 = Hex2DWord(hexvalue1);
        dword2 = Hex2DWord(hexvalue2);
 
        clearblock = TEADecrypt(dword1, dword2, cypherkey);
 
        cleartext += chr( llList2Integer(clearblock, 0) & 0x000000FF);
        cleartext += chr( (llList2Integer(clearblock, 0) & 0x0000FF00)  >> 8);
        cleartext += chr( (llList2Integer(clearblock, 0) & 0x00FF0000)  >> 16);
        cleartext += chr( (llList2Integer(clearblock, 0) & 0xFF000000)  >> 24);
 
        cleartext += chr( llList2Integer(clearblock, 1) & 0x000000FF);
        cleartext += chr( (llList2Integer(clearblock, 1) & 0x0000FF00)  >> 8);
        cleartext += chr( (llList2Integer(clearblock, 1) & 0x00FF0000)  >> 16);
        cleartext += chr( (llList2Integer(clearblock, 1) & 0xFF000000)  >> 24);
 
        hexvalue1  = "";
        hexvalue2  = "";
        dword1    = 0;
        dword2    = 0;
        clearblock = [];
    }
 
     return cleartext;
}
}
 
string decrypt(string password, string message)
list TEAEncrypt(integer dword1, integer dword2,list cypherkey)
{
{
     integer signatureLength = llStringLength(ProtocolSignature);
     integer sum;
     integer headerLength = signatureLength + 12;
     list    cryptlist;
    if(llStringLength(message) < signatureLength + 44)
        return error("Too small for secret message.");
    if(llSubStringIndex(message, ProtocolSignature) != 0)
        return error("Unknown protocol.");
    integer index = signatureLength;
    string major = "0x" + llGetSubString(message, index, ++index);
    string minor = "0x" + llGetSubString(message, ++index, ++index);
    float version = (float)((string)((integer)major) + "." + (string)((integer)minor));
    if(version != ProtocolVersion)
        return error("Unknown version.");
    integer nonce = (integer)("0x" + llGetSubString(message, ++index, index + 7));
    message = llGetSubString(message, headerLength, -1);
    string oneTimePad = llMD5String(password, nonce);
    while(llStringLength(oneTimePad) < (llStringLength(message) / 2 * 3))
        oneTimePad += llMD5String(oneTimePad, nonce);
    oneTimePad = llStringToBase64(oneTimePad);
    message = llXorBase64StringsCorrect(message, oneTimePad);
    message = llBase64ToString(message);
    string digest = llGetSubString(message, 0, 31);
    message = llGetSubString(message, 32, -1);
    if(llMD5String(message, nonce) != digest)
        return error("Message digest was not valid.");
    return message;
}


string hex(integer value)
     integer n = CYCLES;
{
     while (n-- > 0)
     integer digit = value & 0xF;
     string text = llGetSubString(strHex, digit, digit);
    value = (value >> 4) & 0xfffFFFF;
    integer odd = TRUE;
    while(value)
     {
     {
         digit = value & 0xF;
         dword1 = dword1 + ( ( dword2 << 4 ^ ((dword2 >> 5) & 0x07FFFFFF) ) + dword2 ^ sum + llList2Integer(cypherkey, (sum & 3) ) );
        text = llGetSubString(strHex, digit, digit) + text;
         sum += delta;
         odd = !odd;
         dword2 = dword2 + ( ( dword1 << 4 ^ ((dword1 >> 5) & 0x07FFFFFF) ) + dword1 ^ sum + llList2Integer(cypherkey, ((sum >> 11) & 3) ) );
         value = value >> 4;
     }
     }
    if(odd)
        text = "0" + text;
    return text;
}


string encrypt(string password, string message)
     cryptlist = [dword1,dword2];
{
 
    integer nonce = (integer)llFrand(0x7FFFFFFF);
     return cryptlist;
    message = llMD5String(message, nonce) + message;
    string oneTimePad = llMD5String(password, nonce);
    integer count = (llStringLength(message) - 1) / 32;
     if(count)
        do
            oneTimePad += llMD5String(oneTimePad, nonce);
    while(--count);
     return Header + llGetSubString("00000000" + hex(nonce), -8, -1) + llXorBase64StringsCorrect(llStringToBase64(message), llStringToBase64(oneTimePad));
}
}
 
init1()
list TEADecrypt(integer dword1, integer dword2,list cypherkey)
{
{
    list versions = llParseString2List((string)ProtocolVersion, ["."], []);
     integer sum = delta * CYCLES;
    string minor = llList2String(versions, 1);
     list    cryptlist;
     integer p = 0;
     while(llGetSubString(minor, --p, p) == "0");
    Header = ProtocolSignature + hex(llList2Integer(versions, 0)) + hex((integer)llGetSubString(minor, 0xFF000000, p));
}


init2()
    integer n = CYCLES;
{
     while (n-- > 0)
     if(listener != 0)
     {
     {
         llListenRemove(listener);
         dword2 = dword2 - ( ( dword1 << 4 ^ ((dword1 >> 5) & 0x07FFFFFF) ) + dword1 ^ sum + llList2Integer(cypherkey, ((sum >> 11) & 3) ) );
         listener = 0;
         sum -= delta;
        dword1 = dword1 - ( ( dword2 << 4 ^ ((dword2 >> 5) & 0x07FFFFFF) ) + dword2 ^ sum + llList2Integer(cypherkey, (sum & 3) ) );      
     }
     }
     listener = llListen(communicationsChannel, "", NULL_KEY, "");
 
     cryptlist = [dword1,dword2];
    return cryptlist;
}
}
 
default
default
{
{
    state_entry()
    {
        llListenRemove(gListenID);
        gListenID = llListen(communicationsChannel, "", "", "");
        init1();
        init2();
        llOwnerSay("
            Initialisation complete!
            SIMchat online!
            Type /" + (string)communicationsChannel + " and then your message to talk to people that have their channel set the same.
            Touch headset for options.");
        prim_name = "SIMchat(" + llKey2Name(llGetOwner()) + ")";
        prim_desc = "Last reset was: " + llGetTimestamp();
        llSetObjectName(prim_name);
        llSetObjectDesc(prim_desc);
        particle_parameters = [
            PSYS_PART_START_SCALE, <0.02, 0.02, FALSE>, PSYS_PART_END_SCALE, <0.5,0.5, FALSE>,
            PSYS_PART_START_COLOR, <0.94118, 0.00000, 0.23529>,    PSYS_PART_END_COLOR, <1,0,0>,
            PSYS_PART_START_ALPHA, (float) 0.5,        PSYS_PART_END_ALPHA, (float) 0.0,
            PSYS_SRC_BURST_PART_COUNT, (integer)    4,
            PSYS_SRC_BURST_RATE,        (float) 7.5,
            PSYS_PART_MAX_AGE,          (float) 0.5,
            PSYS_SRC_PATTERN, (integer) 1,
            PSYS_PART_FLAGS, (integer) ( 0
                | PSYS_PART_INTERP_COLOR_MASK
            | PSYS_PART_INTERP_SCALE_MASK
            | PSYS_PART_EMISSIVE_MASK
            | PSYS_PART_FOLLOW_SRC_MASK
            | PSYS_PART_TARGET_POS_MASK
            )
                ];
        if ( AUTO_START ) llParticleSystem( particle_parameters );
    }
     on_rez(integer start_param)
     on_rez(integer start_param)
     {
     {
         init1();
         if (llGetOwner() != ownerKey)
         init2();
         {
        llResetScript();
            llReleaseControls();
            llResetScript();
        }
     }
     }
 
     attach(key id)
     changed(integer change)
     {
     {
         if (id)
         if (change & CHANGED_OWNER)
         {
         {
             llOwnerSay("Headset has been reset.");
             llReleaseControls();
             llResetScript();
             llResetScript();
         }
         }
    }
    state_entry()
    {
        ownerKey  = llGetOwner();
        ownerName = llKey2Name(ownerKey);
        cypherkey = [KEY1, KEY2, KEY3, KEY4];


    }
        string timeStamp = llGetTimestamp();
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_NAME, ownerName,
            PRIM_DESC, timeStamp]);
        llRequestPermissions(ownerKey, PERMISSION_TAKE_CONTROLS);


    touch_start(integer total_number)
         llListen(COMM_CHANNEL, "", NULL_KEY, "");
    {
        user = llDetectedKey(0);
        llDialog(user, menu_info_1 + menu_info_2,mainmenu,mChannel);
         llListen(mChannel,llKey2Name(user),user,"");
     }
     }
 
     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {
     {
         if(id==user)
         if (channel != COMM_CHANNEL)
         {
         {
             if(message=="SLURL")
             return;
            {
                Name = llGetRegionName();
                Where = llGetPos();
                X = (integer)Where.x;
                Y = (integer)Where.y;
                Z = (integer)Where.z;
                SLURL = "SLURL for this location is:\n" + "http://slurl.com/secondlife/" + Name + "/" + (string)X + "/" + (string)Y + "/" + (string)Z + "/";
                llSay(0, SLURL);
                return;
            }
            if(message=="SIMchatOFF")
            {
                state sleeping;
                return;
            }
            if(message=="Chat info")
            {
                llOwnerSay("Type /" + (string)communicationsChannel + " and then your message to talk to people that have their channel set the same.");
                return;
            }
            if(message=="Chat howto")
            {
                llOwnerSay("Type in local chat: /" + (string)communicationsChannel + " ...
                    For example: /" + (string)communicationsChannel + " hello, my name is Nick.
                        Everybody in the same SIM using this SIMchat function on channel " + (string)communicationsChannel + " will be able to read what you write.
                            Remember to use channel" + (string)communicationsChannel + "for anything you want to write with this SIMchat-tool. Local chat is limited to 20m radius.");
                return;
            }
            if(message=="RegionCount")
            {
                llOwnerSay("  Region count is now:" + (string)llGetRegionAgentCount());
                return;
            }
            else
            {
                //do nothing
            }
         }
         }
         if (channel == communicationsChannel)
         if (id == ownerKey)
         {
         {
             if (id == llGetOwner())
             llRegionSay(COMM_CHANNEL, Encrypt(message));
             {
             llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ""]);
                llRegionSay(communicationsChannel, encrypt(Password, message));
            llOwnerSay("/me [" + ownerName + "]: '" + message + "'");
                llOwnerSay("You said: " + message);
             llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ownerName]);
             }
        }
            if (llGetAgentSize(id) == ZERO_VECTOR)
        else if (llGetAgentSize(id) == ZERO_VECTOR)
            {
        {
                string message = decrypt(Password, message);
            message = Decrypt(message);
                llOwnerSay((string)name + " said: " + (string)message);
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ""]);
             }
            llOwnerSay("/me [" + name + "]: '" + message + "'");
             llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ownerName]);
         }
         }
     }
     }
}
 
     run_time_permissions(integer perm)
state sleeping
{
    state_entry()
    {
        llOwnerSay("SIMchat offline! Touch headset to go back online.");
        particle_parameters = [];
        if ( AUTO_START ) llParticleSystem( particle_parameters );
    }
 
     touch_start(integer n)
     {
     {
         if (llDetectedKey(0) == llGetOwner())
         if (perm & PERMISSION_TAKE_CONTROLS)
         {
         {
             llOwnerSay("SIMchat back online! Touch headset for further informations.");
             llTakeControls(CONTROL_DOWN, TRUE, TRUE);
            state default;
         }
         }
     }
     }
 
     on_rez(integer start_param)
//  needs a control event for no-script-area hack
     control(key id, integer level, integer edge)
     {
     {
         llResetScript();
         ;
     }
     }
}
}
</lsl>
</source>
[http://wiki.secondlife.com/wiki/User:Kireji_Haiku/SIMchat_headset Go to top!]
 
[[#top|Back to top!]]
</div>
</div>

Latest revision as of 19:11, 24 January 2015

SIMchat headset by Kireji

General information:

If you want to use it, you should drop it into a childprim of a linkset. This setup will give you the possibilty to forward your chat on a certain channel within the whole region your are in and encrypt it. Just make sure anybody you want to talk to has the same variables as you do.

This is what it could look like. There's no particle system in the script, I just added it for demonstration purposes.
Yellow marker shows the root prim (parent), red marker shows the invisible linked prim (child) containing the script.

Back to top!

Script:

//  This script includes the XTEA-LSL-Implementation by:
//  - Morse Dillon
//  - Strife Onizuka
//  - Dedric Mauriac
//  - JB Kraft
//  http://wiki.secondlife.com/wiki/XTEA_Strong_Encryption_Implementation

//  Setup:
//  1. Make sure the object in which you want to use this script has more than one prim.
//  2. Make sure the object is modifiable by you.
//  3. This script must go into a childprim of your object, it doesn't matter into which one.
//  4. After you have copied the script into your object, make sure everyone you want to talk to has the same
//     settings for KEY1, KEY2, KEY3, KEY4 and COMM_CHANNEL. You can use any valid, positive (!) integer number
//     for COMM_CHANNEL excluding PUBLIC_CHANNEL (which is 0) and DEBUG_CHANNEL (which is 2147483647). Do not use
//     a negative channel!
//  5. When chatting, please type in local chat and add your channel. Example: If your COMM_CHANNEL was 9 then you'd type: '/9 hello'
//  6. The code is written for an avatar attachment (usually a headset / HUD) and will run in no-script areas.

 
integer COMM_CHANNEL = 9;
integer KEY1         = 11111111;
integer KEY2         = 22222222;
integer KEY3         = 33333333;
integer KEY4         = 44444444;
 
//  If you're not sure what you're doing,
//  do NOT change anything below!
 
key     ownerKey;
string  ownerName;
 
integer CYCLES    = 6;
 
list    cypherkey;
integer delta     = 0x9E3779B9;
 
integer ord(string chr)
{
    if (llStringLength(chr) != 1)
    {
        return ERR_GENERIC;
    }
    if (chr == " ")
    {
        return 32;
    }
 
    string ASCII = "             \n                    !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    return llSubStringIndex(ASCII, chr);
}
 
string chr(integer i)
{
    i %= 127;

    string ASCII = "             \n                    !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
     return llGetSubString(ASCII, i, i);
}
 
string DWord2Hex(integer m)
{
    string  result;
    integer index;
    string  characters = "0123456789ABCDEF";   
 
    integer i;
    for (; i < 8; i++)
    {
        index  = (m >> (i * 4)) & 0xF;
        result = llInsertString(result, 0, llGetSubString(characters, index, index));
    }
 
    return result;
}
 
integer Hex2DWord(string m)
{
    integer result;
    string digit;
    integer value;
    integer index;
 
    string characters = "0123456789ABCDEF";
 
    integer i;
    for (; i < 8; i++)
    {
        index = 8 - (i + 1);
        digit = llGetSubString(m,index,index);
 
        value = llSubStringIndex(characters, digit);
 
        result = result | value << (i * 4);
    }
 
    return result;
}
 
string Encrypt(string cleartext)
{
    integer cyphertext_numeric;
    integer dword1;
    integer dword2;
    list    cypherblock;
    string  cyphertext;

    while(llStringLength(cleartext) & 0x7)
    {
        cleartext += " ";
    }

    integer character;
    integer stringlength = llStringLength(cleartext); 

    integer i;
    while (i < stringlength)
    {
        dword1 =  ord(llGetSubString(cleartext,i,i));
        i++;
        dword1 =  dword1 | (ord(llGetSubString(cleartext,i,i)) << 8);
        i++;
        dword1 =  dword1 | (ord(llGetSubString(cleartext,i,i)) << 16);
        i++;
        dword1 =  dword1 | (ord(llGetSubString(cleartext,i,i)) << 24);
        i++;

        dword2 =  ord(llGetSubString(cleartext,i,i));
        i++;
        dword2 =  dword2 | ord(llGetSubString(cleartext,i,i)) << 8;
        i++;
        dword2 =  dword2 | ord(llGetSubString(cleartext,i,i)) << 16;
        i++;
        dword2 =  dword2 | ord(llGetSubString(cleartext,i,i)) << 24;
        i++;

        cypherblock = TEAEncrypt(dword1,dword2,cypherkey);

        cyphertext = cyphertext + DWord2Hex(llList2Integer(cypherblock,0)) + DWord2Hex(llList2Integer(cypherblock,1));

        dword1      = 0;
        dword2      = 0;
        cypherblock = [];
     }

    return cyphertext;
}  
 
string Decrypt(string cyphertext)
{
    integer dword1;
    integer dword2;
    list    clearblock;
    string  cleartext;
    string  hexvalue1;
    string  hexvalue2;

    integer i;
    while (i < llStringLength(cyphertext))
    {
        hexvalue1 += llGetSubString(cyphertext,i,i + 7);
        i = i + 8;

        hexvalue2 += llGetSubString(cyphertext,i,i + 7);
        i = i + 8;

        dword1 = Hex2DWord(hexvalue1);
        dword2 = Hex2DWord(hexvalue2); 

        clearblock = TEADecrypt(dword1, dword2, cypherkey);

        cleartext += chr( llList2Integer(clearblock, 0) & 0x000000FF);
        cleartext += chr( (llList2Integer(clearblock, 0) & 0x0000FF00)  >> 8);
        cleartext += chr( (llList2Integer(clearblock, 0) & 0x00FF0000)  >> 16);
        cleartext += chr( (llList2Integer(clearblock, 0) & 0xFF000000)  >> 24);

        cleartext += chr( llList2Integer(clearblock, 1) & 0x000000FF);
        cleartext += chr( (llList2Integer(clearblock, 1) & 0x0000FF00)  >> 8);
        cleartext += chr( (llList2Integer(clearblock, 1) & 0x00FF0000)  >> 16);
        cleartext += chr( (llList2Integer(clearblock, 1) & 0xFF000000)  >> 24);

        hexvalue1  = "";
        hexvalue2  = "";
        dword1     = 0;
        dword2     = 0;
        clearblock = [];
     }

    return cleartext;
}
 
list TEAEncrypt(integer dword1, integer dword2,list cypherkey)
{
    integer sum;
    list    cryptlist;

    integer n = CYCLES;
    while (n-- > 0)
    {
        dword1 = dword1 + ( ( dword2 << 4 ^ ((dword2 >> 5) & 0x07FFFFFF) ) + dword2 ^ sum + llList2Integer(cypherkey, (sum & 3) ) );
        sum += delta;
        dword2 = dword2 + ( ( dword1 << 4 ^ ((dword1 >> 5) & 0x07FFFFFF) ) + dword1 ^ sum + llList2Integer(cypherkey, ((sum >> 11) & 3) ) );
    }

    cryptlist = [dword1,dword2];

    return cryptlist;
}
 
list TEADecrypt(integer dword1, integer dword2,list cypherkey)
{
    integer sum = delta * CYCLES;
    list    cryptlist;

    integer n = CYCLES;
    while (n-- > 0)
    {
        dword2 = dword2 - ( ( dword1 << 4 ^ ((dword1 >> 5) & 0x07FFFFFF) ) + dword1 ^ sum + llList2Integer(cypherkey, ((sum >> 11) & 3) ) );
        sum -= delta;
        dword1 = dword1 - ( ( dword2 << 4 ^ ((dword2 >> 5) & 0x07FFFFFF) ) + dword2 ^ sum + llList2Integer(cypherkey, (sum & 3) ) );        
    }

    cryptlist = [dword1,dword2];
    return cryptlist;
}
 
default
{
    on_rez(integer start_param)
    {
        if (llGetOwner() != ownerKey)
        {
            llReleaseControls();
            llResetScript();
        }
    }
 
    changed(integer change)
    {
        if (change & CHANGED_OWNER)
        {
            llReleaseControls();
            llResetScript();
        }
    }
 
    state_entry()
    {
        ownerKey  = llGetOwner();
        ownerName = llKey2Name(ownerKey);
        cypherkey = [KEY1, KEY2, KEY3, KEY4];

        string timeStamp = llGetTimestamp();
 
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_NAME, ownerName,
            PRIM_DESC, timeStamp]);
 
        llRequestPermissions(ownerKey, PERMISSION_TAKE_CONTROLS);

        llListen(COMM_CHANNEL, "", NULL_KEY, "");
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if (channel != COMM_CHANNEL)
        {
            return;
        }
 
        if (id == ownerKey)
        {
            llRegionSay(COMM_CHANNEL, Encrypt(message));
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ""]);
            llOwnerSay("/me [" + ownerName + "]: '" + message + "'");
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ownerName]);
        }
        else if (llGetAgentSize(id) == ZERO_VECTOR)
        {
            message = Decrypt(message);
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ""]);
            llOwnerSay("/me [" + name + "]: '" + message + "'");
            llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_NAME, ownerName]);
        }
    }
 
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_DOWN, TRUE, TRUE);
        }
    }
 
//  needs a control event for no-script-area hack
    control(key id, integer level, integer edge)
    {
        ;
    }
}

Back to top!