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

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

Asked by 3 years ago

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..

0
i edited my answer, it works now. shadowstorm440 590 — 3y
0
That's the problem, it's too simple. It can be decrypted easily, which makes the choice of encryption redundant. Ziffixture 6913 — 3y

1 answer

Log in to vote
4
Answered by 3 years ago
Edited 3 years ago

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"))
0
I made some errors on accident, I just fixed them. shadowstorm440 590 — 3y
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!!!! WINDOWS10XPRO 438 — 3y
0
hangon i'll edit it. shadowstorm440 590 — 3y
0
i edited it with a "Desub" function. shadowstorm440 590 — 3y
View all comments (5 more)
0
the encoder doesn't seems to work, it prints out "ccc" instead WINDOWS10XPRO 438 — 3y
0
I know why, it's because of it being done all together but some being done before others. shadowstorm440 590 — 3y
0
what WINDOWS10XPRO 438 — 3y
0
I fixed it. shadowstorm440 590 — 3y
0
That's pretty easy to decrypt:/ Ziffixture 6913 — 3y
Ad

Answer this question