Ad
Log in to vote
0

What is wrong with my Encryption script?

Asked by 7 years ago

It isn't working, and I don't understand what the Output means. Here is the script;

function Encryptor(Encrypt)
local String = ""
for i = 1,Encrypt:len() do
String = String..string.char(92)..Encrypt:sub(i,i):byte()
end
end

wait(5)

local cl = script.ScriptBase:Clone()
cl.Code.Value = Encryptor([[print("XD")]])
cl.Parent = game.ServerScriptService
cl.Disabled = false

The Output said; 19:07:29.174 - String expected 19:07:29.175 - Script 'ServerScriptService.Script', Line 12 19:07:29.176 - Stack End

0
Remember that while this may be a good exercise, as an actual security technique is futile and will not protect your code BlueTaslem 18054 — 7y

2 answers

Log in to vote
0
Answered by
Nymint 85
7 years ago

You're missing one line on the function, the famous return

function Encryptor(Encrypt)
local String = ""
for i = 1,Encrypt:len() do
String = String..string.char(92)..Encrypt:sub(i,i):byte()
end
return String --Or any value you're attempting to return.
end

wait(5)

local cl = script.ScriptBase:Clone()
cl.Code.Value = Encryptor([[print("XD")]])
cl.Parent = game.ServerScriptService
cl.Disabled = false

It should work.

0
Thanks, it works! But there is a new error. :/ The Output says `19:44:01.200 - ServerScriptService.ScriptBase:2: attempt to call a nil value 19:44:01.202 - Stack Begin 19:44:01.203 - Script 'ServerScriptService.ScriptBase', Line 2 19:44:01.204 - Stack End`, whats that mean? TheeDeathCaster 2336 — 7y
0
Hmm... That's odd... Could it be because the return is inside the for loop? try moving the return String to in the middle of the two "end"s. That, or I think you actually can't store concatenations in values. Nymint 85 — 7y
Ad
Log in to vote
0
Answered by
BlueTaslem 18054 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

Your function lacks a return, so it evaluates to nil only.

This return must happen after compiling your string.

May I also recommend clearer variable names? Ideally scripts would read fairly naturally outloud. Names like encrypt as the parameter aren't really clear; it should be somethign more like text; we know it is to be encrypted because the function is called Encryptor (although since it is doing something to something, we should probably use the verb, Encrypt)

Also, tabbing is important to code readability!

function Encrypt(Text)
    local EncryptedText = ""
    for i = 1, #Text do
        EncryptedText = EncryptedText .. string.char(92) .. Text:sub(i,i):byte()
    end
    return EncryptedText
end

Remember that any system that just transforms the text like this doesn't actually protect your code if someone gets their hands on all of this: they can just say

loadstring = print

and get everything back.

Answer this question