Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Letter replacer/Language Translator for Fantasy Languages scripting

Coreman Fairport
Registered User
Join date: 6 Apr 2009
Posts: 19
04-25-2009 10:57
I'm trying to make something that works like a translator for chat, either as a seperate hud or in the chat window, that basically replaces english words with a language cipher. Can't find something like this in the wiki's. Please help.

From: Coreman Fairport
Ah, nothing as complex. Sorry for not explaining. Basically I want it to replace every letter with a different letter in a cipher. Not whole words. I found a script that does whole words, and I've been trying to experiment with it but no luck. Anyways an example is a backwards alphabet cipher. Which means
A=Z
B=Y
C=X

And so on. So "Cab" is XZY. Non pronounce-able I know, the other cipher that I really will use is.


From: Papalopulus Kobolowski
Take a look on this maybe can be usefull for you



Alright, I checked out this program, it looks similar to what I want but I am lost on where I put my cipher.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-25-2009 22:00
see string replace
https://wiki.secondlife.com/wiki/Library_Combined_Library

also, most people forget to check these but...
https://wiki.secondlife.com/wiki/Category:LSL_Examples
https://wiki.secondlife.com/wiki/Category:LSL_Library
both are linked from the portal front page

(personally I find those things annoying as well as bloated, but I suppose if you offload it to a webserver you can have a lot more space for the dictionary.)

simple letter scrambles can be done by using parse to list and dump to string on single characters... two sets, first alphabetical, second scrambled, then just use the same index and convert to or from the scramble.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-26-2009 09:18
You could also do something like take the MD5 hash of the word and treat it as a sort of bitstream in which your fantasy word is "encoded". If you could figure out a set of beginning, intermediate, and ending syllables for your fantasy language, use the bits of the hash to pick from those. Obviously you'll have to use part of it to pick the length of the word. You might have a first pass (EDIT: first "pass", not first "past";) phase that translates very common words too (a, the, and, etc.).
Coreman Fairport
Registered User
Join date: 6 Apr 2009
Posts: 19
04-26-2009 11:02
Ah, nothing as complex. Sorry for not explaining. Basically I want it to replace every letter with a different letter in a cipher. Not whole words. I found a script that does whole words, and I've been trying to experiment with it but no luck. Anyways an example is a backwards alphabet cipher. Which means
A=Z
B=Y
C=X

And so on. So "Cab" is XZY. Non pronounce-able I know, the other cipher that I really will use is.
Coreman Fairport
Registered User
Join date: 6 Apr 2009
Posts: 19
04-26-2009 14:01
From: Papalopulus Kobolowski
Take a look on this maybe can be usefull for you



read first post for reply
Papalopulus Kobolowski
working mind
Join date: 11 Aug 2006
Posts: 326
04-26-2009 14:33
ok i look at this script from here



and I made some changes...

From: someone


// www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano)

integer touchedFace;
integer switch;
integer HANDLE;
integer CHANNEL=10;
key owner;

string _key = "scramble";

string keyRepeat(string text, string ky){
integer i;
integer j;
integer l = llStringLength(text);
string out;
for(i = 0; i <= l; ++i){
out += llGetSubString(ky,j,j);
if(j == llStringLength(ky)){
j = 0;
} else {
++j;
}
}
return out;
}

string encrypt(string text, string ky){
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. ,!?&";
ky = keyRepeat(text,ky);
list t = llParseString2List(text,[],[]);
integer l = llGetListLength(t);
integer i;
string o;
integer prev;
for(i = 0; i < l; ++i){
integer x;
integer y = llStringLength(llList2String(t,i));
string ky_temp = llGetSubString(ky,prev,llStringLength(llList2String(t,i)));
prev = llStringLength(llList2String(t,i));
for(x = 0; x < y; ++x){
integer text_p = llSubStringIndex(alphabet,llGetSubString(llList2String(t,i),x,x));
integer key_p = llSubStringIndex(alphabet,llGetSubString(ky_temp,x,x));

integer pos = (text_p + key_p)%57;

o += llGetSubString(alphabet,pos,pos);
}
o += " ";
}
return o;
}

string decrypt(string text, string ky){
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. ,!?&";
ky = keyRepeat(text,ky);
list t = llParseString2List(text,[],[]);
integer l = llGetListLength(t);
integer i;
string o;
integer prev;
for(i = 0; i < l; ++i){
integer x;
integer y = llStringLength(llList2String(t,i));
string ky_temp = llGetSubString(ky,prev,llStringLength(llList2String(t,i)));
prev = llStringLength(llList2String(t,i));
for(x = 0; x < y; ++x){
integer text_p = llSubStringIndex(alphabet,llGetSubString(llList2String(t,i),x,x));
integer key_p = llSubStringIndex(alphabet,llGetSubString(ky_temp,x,x));

integer pos = (text_p - key_p + 57)%57;



o += llGetSubString(alphabet,pos,pos);
}
o += " ";
}
return o;
}










default
{
state_entry()
{

switch=0;
owner=llGetOwner();
llSetObjectName(llKey2Name(owner));

llOwnerSay("Fantasy translators is off and ready!";);




}

changed(integer change)
{
if (change & CHANGED_OWNER)
{

llResetScript();

}
}

touch_start(integer total_number)

{
integer f;
for (f = 0; f < total_number; f++)

{
touchedFace = llDetectedTouchFace(f);// other faces can be usefull for anothers functions on your HUD
if (touchedFace == -1)
{
llWhisper(0, "Sorry, your viewer doesn't support touched faces.";);
}

if(touchedFace==0 && switch==0)
{
switch=1;
HANDLE =llListen(CHANNEL,"","","";);
llOwnerSay("Fantasy translators is on.";);


}
else{
switch=0;
llListenRemove(HANDLE);
llOwnerSay("Fantasy translators is off.";);
}

}
}

listen(integer CHANNEL, string n, key i, string ms)
{



if(switch==1 )

{
if(i == owner)
{

llSay(0,encrypt(ms,_key));

llSay(CHANNEL,encrypt(ms,_key));


}
else
{
llSetObjectName(llKey2Name(i));

llOwnerSay(" says: "+ decrypt(ms,_key));

llSetObjectName(llKey2Name(owner));

}


}
}




}



Its not complete and not fully tested some things can be wrong but can be an start for you.
So any help and modification are very wellcome ;)
_____________________


RAW terrain files - terraform your SIM!!
http://www.wishland.info/
PD:the wiki its your friend ;)
http://wiki.secondlife.com/wiki/LSL_Portal
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-26-2009 18:57
simplified letter replacer function

CODE

string alphabet = "abc.";

string fShiftLetters( string vStrInput integer vIntShift ){
integer vIntCap = llStringLength( vStrInput );
integer vIdxShift;
integer vIntCounter = vIntCap;
while ( vIntCounter-- ){
vIdxShift = llSubStringIndex( alphabet, llGetSubString( vStringInput, 0, 0 ) );
if (~vIdxShift) {
vIdxShift += vIntShift;
}
vStrInput += llGetSubString( alaphabet, vIdxShift, vIdxShift );
}

return llGetSubString( vStrInput, vIntCap, -1 );
}


it'lll shift the alphabet and replace it with the shifted value, or the last character in your custom alphabet if it finds something it doesn't recognize. this can be done quicker for texts larger than the alphabet list by repeated list casts. and this version isn't as memory friendly as it could be (it doubles the input string size) while working... it could easily work by moving the last get substring into the loop, but this runs faster.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -