it really is quite simple, you just use string.gsub()!
read more here: strings
code:
local Alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r","s","t", "u", "v", "w", "x", "y", "z"}
local Encode = {}
local Decode = {}
local function CreateEncode(One, Two)
Encode[#Encode + 1] = {O = One, T = Two}
end
local function CreateDecode(One, Two)
Decode[#Decode + 1] = {O = One, T = Two}
end
local function EncodeString(String)
local Temp = {}
for i = 1,#Encode do
local Split = string.sub(String, i, i)
Split = string.gsub(Split, Encode[i].O, Encode[i].T)
table.insert(Temp, Split)
end
return table.concat(Temp, "")
end
local function DecodeString(String)
local Temp = {}
for i = 1,#Decode do
local Split = string.sub(String, i, i)
Split = string.gsub(Split, Decode[i].O, Decode[i].T)
table.insert(Temp, Split)
end
return table.concat(Temp, "")
end
CreateEncode("a", "b")
CreateEncode("b", "c")
CreateEncode("c", "d")
CreateDecode("b", "a")
CreateDecode("c", "b")
CreateDecode("d", "c")
print(EncodeString("abc"))
print(DecodeString("bcd"))
2 comments
i edited my answer, it works now.
That's the problem, it's too simple. It can be decrypted easily, which makes the choice of encryption redundant.