Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using table.concat separator to print actual text?

Asked by 6 years ago

Hi, I'm trying to make an encrypted message in a particular way.

For instance if i wanted to encrypt "This is a string" I have this;

print(table["concat"]({"", 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67}, "\\"))

Each item in that table is a letter in "This is a string" but in hexadecimal.

However when I run that piece of code what I get is;

\84\104\105\115\32\105\115\32\97\32\115\116\114\105\110\103

However I was looking for

This is a string

Essentially I'm trying to make a one liner and as compact as possible with no upvalues. ie; print"hi";

loadstring(table["concat"]({"", 0x70, 0x72, 0x69, 0x6E, 0x74, 0x22, 0x68, 0x69, 0x22}, "\\"))()

turns into;

loadstring(table["concat"]({"", 0x70, 0x72, 0x69, 0x6E, 0x74, 0x22, 0x68, 0x69, 0x22}, "\"))():1: attempt to call a nil value

I can deal with at most 1 or 2 upvalues but I need a way to tell the game to take the string as escaped characters. I'm also not interested in just;

loadstring("\84\104\105\115\32\105\115\32\97\32\115\116\114\105\110\103")()

I've tried tostring() and tonumber(), However both failed.

Here's my tohex formula;

local src = "r"
print("0x" .. string.format("X", string.byte(src))) -- Still prints 0x72 and not 114, WHY?

Ill keep searching online but this is pretty much where it comes down. Must be concat of hexadecimals and turn out to show the masked text via print or loadstring.

0
out of curiosity, why do you do table["concat"] rather than with dot syntax? no criticism, ive just never seen anyone do that Gey4Jesus69 2705 — 6y
0
It's for that reason. I kind of like using things no one else would try. But now I have a new formatting. LucarioZombie 291 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Alright the fix is just add a loadstring to return the value.

print(loadstring([[return "]] .. table[tostring([[concat]])]({[[]], 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67}, [[]]) .. [["]])[[Fixed]])

>This is a string

Ad

Answer this question