Difference between revisions of "User:Kireji Haiku/SIMchat headset"
Kireji Haiku (talk | contribs) m |
Kireji Haiku (talk | contribs) (Simplyfied!!!) |
||
Line 15: | Line 15: | ||
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. | ||
Line 26: | Line 24: | ||
[[#top|Go to top!]] | [[#top|Go to top!]] | ||
==Script:== | ==Script:== | ||
<lsl> | <lsl> | ||
string ProtocolSignature; | string ProtocolSignature = "ENC";//your signature | ||
float ProtocolVersion; | float ProtocolVersion = 0.3; // can range from 0.0 to 255.255 | ||
string Password; | string Password = "P@ssw0rd";//your password | ||
integer communicationsChannel; | integer communicationsChannel = 9;//the channel you use for communication | ||
string strHex = "0123456789ABCDEF";//hex-password | |||
//############################################################################## | |||
//do not change anything below if you are not 100% sure about what you are doing | |||
//############################################################################## | |||
string Header; | string Header; | ||
integer Debug = TRUE; | |||
integer Debug; | |||
integer listener; | integer listener; | ||
integer gListenID = -1; | integer gListenID = -1; | ||
string prim_name; | string prim_name; | ||
string prim_desc; | string prim_desc; | ||
string | string error(string message) | ||
{ | { | ||
if(Debug) llSay(DEBUG_CHANNEL, message); | if(Debug) llSay(DEBUG_CHANNEL, message); | ||
return ""; | return ""; | ||
} | } | ||
string | string decrypt(string password, string message) | ||
{ | { | ||
integer signatureLength = llStringLength(ProtocolSignature); | integer signatureLength = llStringLength(ProtocolSignature); | ||
Line 155: | Line 71: | ||
string oneTimePad = llMD5String(password, nonce); | string oneTimePad = llMD5String(password, nonce); | ||
while(llStringLength(oneTimePad) < (llStringLength(message) / 2 * 3)) | while(llStringLength(oneTimePad) < (llStringLength(message) / 2 * 3)) | ||
oneTimePad += llMD5String(oneTimePad, nonce); | |||
oneTimePad = llStringToBase64(oneTimePad); | oneTimePad = llStringToBase64(oneTimePad); | ||
message = llXorBase64StringsCorrect(message, oneTimePad); | message = llXorBase64StringsCorrect(message, oneTimePad); | ||
Line 165: | Line 81: | ||
return message; | return message; | ||
} | } | ||
string | string hex(integer value) | ||
{ | { | ||
integer digit = value & 0xF; | integer digit = value & 0xF; | ||
Line 183: | Line 99: | ||
return text; | return text; | ||
} | } | ||
string | string encrypt(string password, string message) | ||
{ | { | ||
integer nonce = (integer)llFrand(0x7FFFFFFF); | integer nonce = (integer)llFrand(0x7FFFFFFF); | ||
Line 190: | Line 106: | ||
string oneTimePad = llMD5String(password, nonce); | string oneTimePad = llMD5String(password, nonce); | ||
integer count = (llStringLength(message) - 1) / 32; | integer count = (llStringLength(message) - 1) / 32; | ||
if(count) do oneTimePad += llMD5String(oneTimePad, nonce); | if(count) | ||
do | |||
oneTimePad += llMD5String(oneTimePad, nonce); | |||
while(--count); | while(--count); | ||
return Header + llGetSubString("00000000" + hex(nonce), -8, -1) + llXorBase64StringsCorrect(llStringToBase64(message), llStringToBase64(oneTimePad)); | return Header + llGetSubString("00000000" + hex(nonce), -8, -1) + llXorBase64StringsCorrect(llStringToBase64(message), llStringToBase64(oneTimePad)); | ||
} | } | ||
init1() | init1() | ||
{ | { | ||
Line 203: | Line 121: | ||
Header = ProtocolSignature + hex(llList2Integer(versions, 0)) + hex((integer)llGetSubString(minor, 0xFF000000, p)); | Header = ProtocolSignature + hex(llList2Integer(versions, 0)) + hex((integer)llGetSubString(minor, 0xFF000000, p)); | ||
} | } | ||
init2() | init2() | ||
{ | { | ||
Line 213: | Line 131: | ||
listener = llListen(communicationsChannel, "", NULL_KEY, ""); | listener = llListen(communicationsChannel, "", NULL_KEY, ""); | ||
} | } | ||
default | default | ||
{ | { | ||
state_entry() | state_entry() | ||
{ | { | ||
llListenRemove(gListenID); | llListenRemove(gListenID); | ||
gListenID = llListen(communicationsChannel, "", "", ""); | gListenID = llListen(communicationsChannel, "", "", ""); | ||
init1(); | init1(); | ||
init2(); | init2(); | ||
llOwnerSay("\n \n \n \nInitialisation complete!\nSIMchat online!\nType /" + (string)communicationsChannel + " and then your message to talk to people that have their channel set to the same."); | |||
prim_name = "SIMchat(" + llKey2Name(llGetOwner()) + ")"; | prim_name = "SIMchat(" + llKey2Name(llGetOwner()) + ")"; | ||
prim_desc = "Last reset was: " + llGetTimestamp(); | prim_desc = "Last reset was: " + llGetTimestamp(); | ||
llSetObjectName(prim_name); | llSetObjectName(prim_name); | ||
llSetObjectDesc(prim_desc); | llSetObjectDesc(prim_desc); | ||
} | } | ||
on_rez(integer start_param) | on_rez(integer start_param) | ||
{ | { | ||
llResetScript(); | llResetScript(); | ||
} | } | ||
attach(key id) | |||
{ | { | ||
if ( | if (id) | ||
{ | { | ||
llOwnerSay("Resetting scripts..."); | |||
llResetScript(); | |||
} | } | ||
} | } | ||
listen(integer channel, string name, key id, string message) | listen(integer channel, string name, key id, string message) | ||
{ | { | ||
if (channel == communicationsChannel) | if (channel == communicationsChannel) | ||
{ | { | ||
Line 389: | Line 177: | ||
} | } | ||
} | } | ||
} | } | ||
} | } |
Revision as of 01:24, 21 December 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Check out all my other projects!
SIMchat headset
General information:
This script is being provided "as is". It's been thoroughly tested in May 2010.
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.
Script:
<lsl> string ProtocolSignature = "ENC";//your signature float ProtocolVersion = 0.3; // can range from 0.0 to 255.255 string Password = "P@ssw0rd";//your password integer communicationsChannel = 9;//the channel you use for communication string strHex = "0123456789ABCDEF";//hex-password
//############################################################################## //do not change anything below if you are not 100% sure about what you are doing //##############################################################################
string Header;
integer Debug = TRUE;
integer listener;
integer gListenID = -1;
string prim_name;
string prim_desc;
string error(string message) {
if(Debug) llSay(DEBUG_CHANNEL, message); return "";
}
string decrypt(string password, string message) {
integer signatureLength = llStringLength(ProtocolSignature); integer headerLength = signatureLength + 12; 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 digit = value & 0xF; string text = llGetSubString(strHex, digit, digit); value = (value >> 4) & 0xfffFFFF; integer odd = TRUE; while(value) { digit = value & 0xF; text = llGetSubString(strHex, digit, digit) + text; odd = !odd; value = value >> 4; } if(odd) text = "0" + text; return text;
}
string encrypt(string password, string message) {
integer nonce = (integer)llFrand(0x7FFFFFFF); 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 versions = llParseString2List((string)ProtocolVersion, ["."], []); string minor = llList2String(versions, 1); integer p = 0; while(llGetSubString(minor, --p, p) == "0"); Header = ProtocolSignature + hex(llList2Integer(versions, 0)) + hex((integer)llGetSubString(minor, 0xFF000000, p));
}
init2() {
if(listener != 0) { llListenRemove(listener); listener = 0; } listener = llListen(communicationsChannel, "", NULL_KEY, "");
}
default {
state_entry() { llListenRemove(gListenID); gListenID = llListen(communicationsChannel, "", "", ""); init1(); init2(); llOwnerSay("\n \n \n \nInitialisation complete!\nSIMchat online!\nType /" + (string)communicationsChannel + " and then your message to talk to people that have their channel set to the same."); prim_name = "SIMchat(" + llKey2Name(llGetOwner()) + ")"; prim_desc = "Last reset was: " + llGetTimestamp(); llSetObjectName(prim_name); llSetObjectDesc(prim_desc); } on_rez(integer start_param) { llResetScript(); } attach(key id) { if (id) { llOwnerSay("Resetting scripts..."); llResetScript(); } } listen(integer channel, string name, key id, string message) { if (channel == communicationsChannel) { if (id == llGetOwner()) { llRegionSay(communicationsChannel, encrypt(Password, message)); llOwnerSay("You said: " + message); } if (llGetAgentSize(id) == ZERO_VECTOR) { string message = decrypt(Password, message); llOwnerSay((string)name + " said: " + (string)message); } } }
} </lsl> Go to top!