Game Development Community

String Manipulation in TGE

by Christopher Dapo · in Torque Game Engine · 03/03/2007 (2:37 pm) · 30 replies

EDIT: -!!New Problem Listed Below!!-

I've searched around for information on manipulating strings in Torque and I still have a problem.

My problem:
I need to figure out how to 'read' characters from strings so they can be managed.

So far:
The closest I've come to figuring this out is from TDN:
- TS Console Functions 3 - strlen(string //used to determine string length of chars

...The question is, what other syntax can I use to retrieve characters from the string

Example:
myString = "abcdefg012345"
for(curChar = 0, curChar < strlen(myString), curChar++)
{
getNextChar //how do I?

Any help is appreciated, thank you!
Page «Previous 1 2
#1
03/03/2007 (3:07 pm)
GetSubStr () would work.
#2
03/06/2007 (2:30 am)
Thanks a bunch Stefan! Now that I've had some time to think about it - I think I can get this to work!

%myString = "ThisIsMyString"
startPos = 6
endPos = 7
startPos2 = 3
endPos2 = 5
%fromMyString = (getSubStr(%myString,startPos,endPos) + " " + getSubStr(%myString,startPos2,endPos2));

The result should be:
Quote:
%fromMyString = "My sIs"

I'll let you know how it goes. If all goes well I'll hook you up with what I'm doing with this!
#3
03/06/2007 (2:40 am)
Hehe, that is confusing stuff.
#4
03/06/2007 (5:31 am)
I'm working on integrating my Ronzcode into TGE! This'll be fun!

Imagine a chest. Inside is the loot, but where's the key? What if it was in the chest?! What if it only opened itself to who owned it?!

See where I'm going with this?

The code generator will take some time but the main thing I need to do is the decoder, which is what I needed this for!

Let you know once I've set up the first 36 characters (alphabet+numbers) and I'll let you demo it!

BTW, the confusing part is how simple this really is!
#5
03/06/2007 (2:50 pm)
Ok, I just need a little more info.

First off, is there a limit to how many characters there can be in strings?

Right now, I'm at 578 characters in just about 1/5th of the string!! That covers 96 keyboard characters - Upper-/Lower-case alpha; numbers 0-9; special characters.

Also, what about the special characters, is there a list of what characters I may/may not use in strings?

I want to be able to account for all available/possible. This way, I can encrypt entire lines of code.

Oh, one more good question - after compilation and distribution, how modifiable is the code? Can script be "pasted in" in the background? If not, what about into a placeholder file used just for cutting/pasting and passing the data?

If anyone can still point out a way to read strings character-for-character, I think it would make things much smoother. Any help is appreciated, thanks!

- Ronixus
#6
03/06/2007 (3:10 pm)
You can definatly stuff more than 578 characters into a Torque Script string. I think the limit lies somewhere around 4095.
#7
03/06/2007 (5:25 pm)
Aha! eval(%string) should do the trick after decryption! I need more info on this...
#8
03/07/2007 (5:58 am)
Okay!

function myWork(%mystring)
{
  //First we break it up correctly
  %myLong = strLen(%mystring);
  %myone = getSubStr(%mystring,0,198);
  %mytwo = getSubStr(%mystring,198,198);
  %myCode = getSubStr(%mystring,396,(%myLong - 396));
  %mypart = (strLen(%myCode)/4);
  %mythree = getSubStr(%myCode,0,%mypart);
  %myfour = getSubStr(%myCode,%mypart,%mypart);
  %myfive = getSubStr(%myCode,(%mypart*2),%mypart);
  %mysix = getSubStr(%myCode,(%mypart*3),%mypart);
  //Check our results
  echo("String Overall Length = " @ %myLong NL "Keys = " @ %myone NL %mytwo NL "Rest Of String = " @ (%mypart*4) 

NL "Parts: " NL %mythree NL %myfour NL %myfive NL %mysix);
  return 0;
}
//some test subjects, hehe
%csTest = "IMABIGFATFUNKYLIARandS0lidarity1ders0IdunNOalot?whattheholeisGOING 0n Here Huh??!! oh, my god, not him, not 

HIMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM!!!!!!!!!!!012101210121012101210121012101210121012101210121000022221102212333232222222

222222222222222222222222222??andwhoareyou?lotsandlotsandlotsandLOTSofgoodhotsweatyprogrammingfun,btw....ah, what else is 

there,hmmmmmmmmmmmmmmmmmmmmmmmm...1234543456765678987890909090909090909090909090909090ohwhatever!!!!!!!!!!!!!0000000000111111

111111111199999999222222228888888888888833333333333777777777777777777";

mywork(%csTest);

So far, so good! I've got most of the reading done, now to cut it up and decode it!

This is the fun part!!!

Test Results:
String Length = 548
part 1 = 198
part 2 = 198
part 3 = 38
part 4 = 38
part 5 = 38
part 6 = 38

Had 1 syntax error (had added an extra semi-colon, lol)

Next step is to complete the decoding using some looping organization and (maybe) some clever arrays.

Once I get it running smooth feel free to ask for a test sample to see my encryption in action!

Later!

- Ronixus
#9
03/07/2007 (6:24 am)
Oh, I recognize your name now.

A few questions:
1. What would you use this so called encryption for?
2. Is this like your previous scrambler? (here and here.)
3. What prevents someone from looking at the code in a disassembler, and reversing it?
4. Are you using the same key for encryption and decryption?
4b. If so, how do you exchange the key without a middle man seeing it?
5. Why would anyone use this as opposed to: AES, TEA, RSA?
#10
03/10/2007 (12:42 am)
I thought you might ;)

A few answers:
1) This can be used in place of key program elements to limit the accessability from directly within the program itself and the possabilities are limited only by the freedom to manipulate the data. Eventually, once the code can be generated on-the-fly, I could easily bundle the entire game into a demo with limited access untill the purchase is made or even limit the time to access the full game before it reverts back into demo mode! I can lock out editors, cheats, even entire portions (ex: rewrite main.cs into full code) and have them replaced randomly every time the program starts.
2) Yup!
3) For one, the code consists of a few different encryptions all at once. This means, even if you managed to pull out the original form of the code...then broke it down into it's second form...and it's third form...you still have to have a way to figure out how it all works together to even come close to uncovering the key... then there's deciphering that and the actual raw code form.
Secondly, the code is reworked through a combination of identifiers and structural dependancies, resulting in a code that can only work the correct way - and considering the randomness of the structures, the identifiers, and the code itself, not to mention the fact that, outside of the mechanics of the reconstruction system there's no other indications of what the code provides for untill it's filled in, there's not much to go on other than knowing that it's hiding something.
I guess the biggest cover-up is that it's actually quite simple once you see how it works, it's just been reworked into a complex randomness (yet it's actually quite accurate) that disguises how it could be reinterpreted.
4) Same basic key structure, but not ever the same key! The structure of the code can be restructured if I want it to be, though, I don't see too much point inmaking it more complicated just yet. The structure is quite sound and well defined the way it is. So, now you could probably ask,"What if someone figures out the structure?" They would have to figure out how it all works together to even get an indication of how to break it down into any legitimate form of comprehension. In other words, you could swap this on paper with a friend who knew how to break it all down, but even they would have a tough time decoding it due to the complexities of the encryption.
4b) Remember, the entire code also has it's own key embedded in it every time, so even the program that decodes it has no idea how to decode it untill it receives the proper flow of the restructuring proccess. Clever I think! This means it dosen't matter if anyone sees the exchange, it's a bunch of random garbage (well, some of it isn't because I can rearrange the code to show all kinds of messages in it's viewable form, hehe). Go ahead, play with the concept of cracking it, but when your head catches fire and explodes, don't say I didn't warn you of the thought that went into making it a headache. Shoot, I'd almost want to share the secret only to laugh at them when they cry from how simple it really is!
5) Increased security independant of anything else! It can be used to secure anything and it can be done genuinly from the programmer's perspective in every instance. What could be better than a developers own optional complexities in their code?! Where they want it, however much they want to conceal, it's all optional! In enough time, I could probably break down most aspects of (for instance) TGE so that there would appear to be nothing more than a few routines, the code hiding the rest, enough to start the program and start decoding the portions it requires to be "installed and compiled" on-demand!

As of recently I've completed the first key for the program I'm developing and (given there are no complications with using special characters in TScript strings) it now covers all possible data in relation to a standard PC keyboard printed characters! As I mentioned before, the key is 578 characters long. Now it's finally been defined for my example code which I'll use to demo my work! All it'll take is sending the code to be pasted into a .cs file for compilation in order to run it, and hey, then you can try and figure out what it's doing by following the script...good luck!

I'll even paste it here for demo once it's done (unless someone suggests against it...ahem...) that way anyone can see it work it's magic for themselves!

After the complete system is complete, I'll probably set it up as a mod pack.

All for now!

- Ronixus
#11
03/12/2007 (3:34 am)
Ok guys, here's one for you to help me figure out...

The following is straight from my code project. I keep recieving an error in the following code and I need some help figuring out what it is!

I currently run this appended to clientGame.cs in GameOne:
// Start my code!

function rcDcode(%rcstring)
{
  //First we break it up correctly
  %rcLong = strLen(%rcstring);
  %rcKone = getSubStr(%rcstring,0,288);
  %rcKtwo = getSubStr(%rcstring,288,288);
  %rcCode = getSubStr(%rcstring,576,(%rcLong - 576));
  %rcCpart = (strLen(%rcCode)/4);
  %rcCone = getSubStr(%rcCode,0,%rcCpart);
  %rcCtwo = getSubStr(%rcCode,%rcCpart,%rcCpart);
  %rcCtri = getSubStr(%rcCode,(%rcCpart*2),%rcCpart);
  %rcCfor = getSubStr(%rcCode,(%rcCpart*3),%rcCpart);
  //Check our results
  echo("String Overall Length = " @ %rcLong NL "Keys = " @ %rcKone @ ", and " @ %rcKtwo NL "Full Code Size = " @ (%rcCpart*4) 

NL "Code Parts: " NL %rcCone NL %rcCtwo NL %rcCtri NL %rcCfor);
  return 0;
}

%csTest = "9A79B19C49D=8EXAF27G)BH(6IXCJ)5K(DL?4M?EN?3OSFPu2Qc1RkSSS0T,1UH2Vu3WhKXuAYXDZiD Np_6A-5y=2ya1ybyKcy0dyEeNFfO>g oh 

<iDGj*Ok;Dl+&m~Cnm0oa.pt-q=IrSRs	 t UuFRv. wAAxS 

yS0z00.0v,96!v5?3e/Cm|oa\pi<yl^r:>ir0go1hn2ti32x40u50s67_7FX8r@9oN@mR*CT$IO%?T&AX+^O"^-'^I;-S:RI~'A#L9'?6	

N=(_0)0([-O)-){  }081o73p65e57n46s34e22a11s03a 5m	7e 6!	4!B2!U1 T3DT5aS7AT6MI4NC2UK1gR3op5tu7in6t 

4!72C41O33D05Ey7ko6e04ye2LN1UM3C^5KM7o?6SY4yo2sC1ty3ea5MM7OA6uN4TN2	

u1NO3CL5.b7Mi6ot4Fc2oh1!830751472A6-D4CD2hR1rE3iS5sy7ta6oh4po2ho1e.3rc5 o7Dm6a-4pO2oU1TH3ST5!H7Tv6XN4 

o2-M1-O3Yt5sL7>06!O4EE20=1DM3uC5h244 2X012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012

34567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567

89098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098

76543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543

21012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012

34567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567

89098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098

765432101234567890987654321012345678909876543210123456789098765432101234567890987654321"

rcDcode(%csTest);

console log reports:
Compiling GameOne/client/clientGame.cs...
GameOne/client/clientGame.cs Line: 33 - parse error
>>> Advanced script error report.  Line 33.
>>> Some error context, with ## on sides of error halt:
T5!H7Tv6XN4 o2-M1-O3Yt5sL7>06!O4EE20=1DM3uC5h244 2X012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321";
>>> Error report complete.

What's the problem?! Anyone?

Currently, my guess is that either:
1) Not liking the special characters.
2) There is a limit to string length shorter than anticipated (notice how it doesn't report the entire string, just starting at ...4pO2oU1TH3S(here)T5!H7Tv6XN4 ...)

It doesn't make sense!
#12
03/12/2007 (7:41 am)
Im guessing :
1) Not liking the special characters.
#13
03/12/2007 (8:38 am)
Try to close each line before writing a new one.

Like:

%string = "dumdidumdumdum" @
"damdamdam" @
"demdemdem";
#14
03/12/2007 (9:38 pm)
Quote:
Try to close each line before writing a new one.

That would be nice if there were more than one line:

%csTest = "9A79B19C49D=8EXAF27G)BH(6IXCJ)5K(DL?4M?EN?3OSFPu2Qc1RkSSS0T,1UH2Vu3WhKXuAYXDZiD Np_6A-5y=2ya1ybyKcy0dyEeNFfO>g oh <iDGj*Ok;Dl+&m~Cnm0oa.pt-q=IrSRs	 t UuFRv. wAAxS yS0z00.0v,96!v5?3e/Cm|oa\pi<yl^r:>ir0go1hn2ti32x40u50s67_7FX8r@9oN@mR*CT$IO%?T&AX+^O"^-'^I;-S:RI~'A#L9'?6	N=(_0)0([-O)-){  }081o73p65e57n46s34e22a11s03a 5m	7e 6!	4!B2!U1 T3DT5aS7AT6MI4NC2UK1gR3op5tu7in6t 4!72C41O33D05Ey7ko6e04ye2LN1UM3C^5KM7o?6SY4yo2sC1ty3ea5MM7OA6uN4TN2	u1NO3CL5.b7Mi6ot4Fc2oh1!830751472A6-D4CD2hR1rE3iS5sy7ta6oh4po2ho1e.3rc5 o7Dm6a-4pO2oU1TH3ST5!H7Tv6XN4 o2-M1-O3Yt5sL7>06!O4EE20=1DM3uC5h244 2X012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321012345678909876543210123456789098765432101234567890987654321"

Maybe that's the problem.

Anyone?
#15
03/14/2007 (1:42 pm)
Missing ; at the end of that line?
#16
03/14/2007 (3:44 pm)
Yup, you are not closing the string.
#17
03/15/2007 (6:09 am)
Your string has a double quote in it. Always the first port of call when you get errors halfway through a string, look for double quotes. Or use a syntax checker.

Then there's the missing semi-colon at the end of the line.

Boggles the intelligence of many, that one. ;)
#18
03/15/2007 (6:18 am)
O[b]"[/b]^
#19
03/16/2007 (6:48 am)
I also noticed *Ok; in your string. Can the semi-colon be in a string like that?
#20
03/16/2007 (6:59 am)
Should be no problem mb.
Page «Previous 1 2