## Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

# Discussion: Bitwise rotation

Eric Quine
Registered User
Join date: 5 Jun 2006
Posts: 3
07-04-2007 10:48
CODE
`string RotateBits(string bits, integer amount, string direction){    integer x;    integer size = llStringLength(bits) - 1;    string value;    if(direction == "RIGHT")    {        for (x = 0; x < amount; x++)        {            string val = llGetSubString(bits, size, size) +            llDeleteSubString(bits, size, size);            value = val;            bits = value;}        }    if(direction == "LEFT")    {        for (x = 0; x < amount; x++)        {            string a = llGetSubString(bits, 0, 0);            string b = llDeleteSubString(bits, 0, 0);            value = b+a;            bits = value;}        }    return value;}string RotateMultipleBits(string bits, integer stride, integer amount, string direction){    integer length = llStringLength(bits);    integer x;    string value;        for ( x = 0; x < length; x+=stride )    {        string b = llGetSubString(bits, x, x+stride-1);        string v = RotateBits(b, amount, direction);        value += v;    }    return value;}`

was playing about and figured this could be a little useful for someone trying to create an encryption, rotation is rather simple and you can easily recover the original bit of info by rotating it back as many times as you rotated it forward, these functions are for rotating binary but any string you put in will be rotated since its not much of a mathematical function as it is just re formating strings, they work like so:

__________________________________________________

RotateBits("0001", 1 , "RIGHT";

that is saying you want to rotate "0001" one time to the right,

any amount of bits put into this function will work.

it will rotate a nybble, or a byte, and so on so fourth.

__________________________________________________

RotateMultipleBits("1101111010101101", 4, 1, "RIGHT";

that is saying you want to rotate every four bits in the binary 1 time to the right,
more easily looked at like this:

1101 1110 1010 1101 each section one time to the right equals this 1110 0111 0101 1110.

(do not put spaces in the bits you want to rotate, that was just easier to look at.)

__________________________________________________

this is the format for each

RotateBits(string bits, integer amount, string direction)

bits is what you are rotating, amount is by how much, and direction is which way "LEFT or RIGHT"

RotateMultipleBits(string bits, integer stride, integer amount, string direction)

its almost the same as the last, except for stride, which is how many bits at a time to rotate.

__________________________________________________

these both return strings.

you need to have both for the RotateMultipleBits function to work since they are dependent of one another.

enjoy :3
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
07-12-2007 22:23
/15/de/195298/1.html
_____________________
i've got nothing.
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
07-13-2007 07:04
I haven't tested it, since I'm not on SL atm, but I think this RotateBits function will work faster:

string RotateBits(string bits, integer amount, string direction)
{
if (direction == "RIGHT"
{
return llGetSubString(bits, -amount, -1) + llGetSubString(bits, 0, -amount - 1);
}
if (direction == "LEFT"
{
return llGetSubString(bits, amount, -1) + llGetSubString(bits, 0, amount - 1);
}
return bits;
}

I wouldn't call it "RotateBits" btw, since you're rotating characters, not bits.

Lyn
Bobbyb30 Zohari
SL Mentor Coach
Join date: 11 Nov 2006
Posts: 466
12-06-2007 12:51
Seems extremely useful. Not a powerful encyrption, but something nonethe least.

Has anyone tested this for bugs?
_____________________
Bobbyb30 Zohari
SL Mentor Coach
Join date: 11 Nov 2006
Posts: 466
12-07-2007 14:22
Also how exactly do you use that RotateMultipleBits?
_____________________
Bobbyb30 Zohari
SL Mentor Coach
Join date: 11 Nov 2006
Posts: 466
12-07-2007 14:45
I'd also like to have permission to post this in the lsl scripting library.
_____________________
Bobbyb30 Zohari
SL Mentor Coach
Join date: 11 Nov 2006
Posts: 466
12-07-2007 15:01
I'd also like to have permission to post this in the lsl scripting library wiki.
_____________________
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-07-2007 17:42
if you have the last post, rather than making a new one, just edit the previous one... no need to bump a thread unless it's falling off the page.

and which LSL library are you wanting to post it to? it's a discussion thread so it's in the forum one, did you mean one of the wikis?
_____________________
|
| . "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...
| -
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-07-2007 23:06
To rotate right, just use a negative amount.
CODE
`string RotateLeft(string in, integer amount){    amount = amount % llStringLength(in);    return llGetSubString(in, amount, -1) + llDeleteSubString(in, amount, -1);}`
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Bobbyb30 Zohari
SL Mentor Coach
Join date: 11 Nov 2006
Posts: 466
12-08-2007 09:48
From: Strife Onizuka
To rotate right, just use a negative amount.
CODE
`string RotateLeft(string in, integer amount){amount = amount % llStringLength(in);return llGetSubString(in, amount, -1) + llDeleteSubString(in, amount, -1);}`

That seems to work, but how do you use the multiple bit rotation. I can't get it to rotate and then unrotate...
_____________________
Bobbyb30 Zohari
SL Mentor Coach
Join date: 11 Nov 2006
Posts: 466
12-10-2007 14:54
Anyone?
_____________________
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
12-10-2007 15:21
feed it the inverse of the number you used to rotate it? or perhaps the segment length, minus your initial rotation amount
_____________________
|
| . "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...
| -
Wyatt Burton
Registered User
Join date: 11 Jan 2007
Posts: 49
12-11-2007 06:32
From: Lyn Mimistrobell
I haven't tested it, since I'm not on SL atm, but I think this RotateBits function will work faster:

string RotateBits(string bits, integer amount, string direction)
{
if (direction == "RIGHT"
{
return llGetSubString(bits, -amount, -1) + llGetSubString(bits, 0, -amount - 1);
}
if (direction == "LEFT"
{
return llGetSubString(bits, amount, -1) + llGetSubString(bits, 0, amount - 1);
}
return bits;
}

I wouldn't call it "RotateBits" btw, since you're rotating characters, not bits.

Lyn

+1