hello, fellow scripters! so I am making a decrypter to decrypt my encryption, and this part is not working. for example, the decryption may be 23059140-23025582-23006406. (that is pie encrypted) and I need to put each lot of numbers in a table, so I made this:
function decrypt(code, PIN) local decryption = {} local ryt = 0 print("decrypting") local lengnthy = string.len(code) local len = string.len(code) for i = 1, len do wait(0.000000000001) print("yeet") local tg = {} for y = ryt, len do print(ryt) print("yeeeeee") wait(0.0000001) local letter = string.sub(code, y,y) print(letter) if letter == "-" then break else table.insert(tg, letter) end end print("decrypting letter") local full = table.concat(tg, "") print(full) local yeet = full / PIN yeet = full - PIN --there is more down here, buti did not put it in.
the problem is, the first letter it prints is "-" when it is SUPPOSED to be 2. (line 17). can somebody help me?
You are overcomplicating things. I recommend that you use string.gsub
or string.gmatch
instead.
string.gsub
string.gsub(s, pattern, repl)
returns a copy of s in which all (or the first n, if given) occurrences of the pattern have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred.
In your case, simply replace all hyphens "-" with an empty string "":
local full = string.gsub(code, "-", "")
string.gmatch
string.gmatch(s, pattern)
returns an iterator function that, each time it is called, returns the next captures from pattern over the string s. This is great for storing each character at a unique table index.
In your case, simply match all characters except for hyphens:
local tg = {} local i = 1 for c in str:gmatch("[^-]") do tg[i] = c i = i + 1 end