|
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
|
10-04-2008 00:03
string s_SeededRandomString(string f_Seed1, string f_Seed2) { string f_Hash = llMD5String(llXorBase64StringsCorrect( llStringToBase64(f_Seed1),llStringToBase64(f_Seed2)), 0); string f_Characters = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-+"; //" + " due to forced forum spacing, removable. string f_String; integer f_StrLen = 0; while(f_StrLen < 16) { integer f_Int = llFloor((integer)("0x"+llGetSubString(f_Hash, f_StrLen * 2, f_StrLen * 2 + 1)) / 4); f_String += llGetSubString(f_Characters, f_Int, f_Int); f_StrLen += 1; } return f_String; }
XORs 2 input strings together, MD5s the result and uses each pair of bits to generate integers to pull out of the character list.
Works excellently for mine, and possibly others' uses, however I don't know how to approach getting potential output size above 16 characters... Is there any application where it'd be necessary to have more than 16?
Credits so far: bobbyb30 Swashbuckler - for the "Hey, you're not actually doing anything!" - Added the XOR to make it actually do something.
|
|
bobbyb30 Swashbuckler
Registered User
Join date: 8 Sep 2008
Posts: 46
|
10-04-2008 11:06
From: Faust Vollmar string s_SeededRandomString(string f_Seed) { string f_String; string f_Hash = llMD5String(f_Seed, 0); string f_Characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-+"; while(llStringLength(f_String) < 16) { integer f_Grab1 = llStringLength(f_String) * 2; integer f_Grab2 = llStringLength(f_String) * 2 + 1; integer f_Grab = (integer)("0x"+llGetSubString(f_Hash, f_Grab1, f_Grab2)); integer f_GrabDiv = llFloor(f_Grab / 4); f_String += llGetSubString(f_Characters, f_GrabDiv, f_GrabDiv); } return f_String; } Works excellently for mine, and possibly others' uses, however I don't know how to approach getting potential output size above 16 characters... Is there any application where it'd be necessary to have more than 16? EDIT2: Anyone who saw the security risk issue, I resolved it fairly easily, so again I make the string generator available. =p So what does this exactly do?
_____________________
Large supporter and contributer of LSL Editor available at lsleditor.org
|
|
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
|
10-04-2008 13:00
It's like the random string function, except output is predictable and will always be the same with the same seed. Sometimes you need to be able to coordinate the string being used without relying on a central object to send the string to everything. (Like I do.)
MD5ing the seed results in 32 hex characters. The while loop takes 2 at a time, makes an integer out of em, divides the result by 4 (list is only 64 chars) and repeats until the MD5 string is used.
EDIT: This one is probably less cluttered as far as working. **Removed to Declutter**
|
|
bobbyb30 Swashbuckler
Registered User
Join date: 8 Sep 2008
Posts: 46
|
10-04-2008 18:09
From: Faust Vollmar It's like the random string function, except output is predictable and will always be the same with the same seed. Sometimes you need to be able to coordinate the string being used without relying on a central object to send the string to everything. (Like I do.) MD5ing the seed results in 32 hex characters. The while loop takes 2 at a time, makes an integer out of em, divides the result by 4 (list is only 64 chars) and repeats until the MD5 string is used. EDIT: This one is probably less cluttered as far as working. string s_SeededRandomString(string f_Seed) { string f_Hash = llMD5String(f_Seed, 0); string f_Characters = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-+"; //" + " due to forced forum spacing, removable. string f_String; integer f_StrLen = 0; while(f_StrLen < 16) { integer f_Int = llFloor((integer)("0x"+llGetSubString(f_Hash, f_StrLen * 2, f_StrLen * 2 + 1)) / 4); f_String += llGetSubString(f_Characters, f_Int, f_Int); f_StrLen += 1; } return f_String; } so basically its a hash? How does it differ from md5? and wouldn't it be weaker?
_____________________
Large supporter and contributer of LSL Editor available at lsleditor.org
|
|
Faust Vollmar
llSetAgentSanity(FALSE);
Join date: 3 Feb 2007
Posts: 87
|
10-04-2008 18:23
*shrug* Guess this is what happens when I've had little sleep and have been drinking. >.>
EDIT: *lightbulb* Perhaps calling for 2 seed strings and
string f_Hash = llMD5String( llXorBase64StringsCorrect( llStringToBase64(f_Seed1), llStringToBase64(f_Seed2) ), 0);
instead of MD5ing 1 string?
|