Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I change a specific string or called char to another?

I wanted to make a word shifter for roblox, since my friend gave me the idea.. The thing is, I don't know how I can change the specific string to another when the button "Encode" is clicked.

I want the string to be change to the next alphabet for example

if they type abc in the textbox when they click encode, it will be bcd

word shifter will shift the alphabet to another which means a=b b=c c=d e=f

and so on Please help me!! I know its super simple to you awesome programmers!!! So Please Help Me Out..

2 comments

0

i edited my answer, it works now.

0

That's the problem, it's too simple. It can be decrypted easily, which makes the choice of encryption redundant.

1 answer

✓ Accepted answer

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"} -- just incase you wanna do it easier for decode and encode.

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"))

9 comments

0

I made some errors on accident, I just fixed them.

0

how do I make a decode for that like when it's bcd, and I decode it become abc again. I made the encode though! THANKS!!!!

0

hangon i'll edit it.

0

i edited it with a "Desub" function.

0

the encoder doesn't seems to work, it prints out "ccc" instead

0

I know why, it's because of it being done all together but some being done before others.

0

what

0

I fixed it.

0

That's pretty easy to decrypt:/

This discussion is preserved as it was. New answers, comments, and votes are closed.