So basically I am making a puzzle game and I am trying to script a cipher the cipher I am using is the a1z26 so basically a = 1 b = 2 c = 3 d = 4 ... z = 26 and yeah I have the code set up but I don't know how to convert the text into numbers I have the tables set up and yeah here is the script
AlphabetTbl = {} Alphabet = "abcdefghijklmnopqrstuvwyxABCDEFGHIJKLMNOPQRSTUVWXYZ " for i = 0,#Alphabet,1 do AlphabetTbl[i] = string.sub(Alphabet, i, i) end function encrypt(txt) for i = 0,#txt, 1 do print() end end
So yeah the alphabet table is going to be every letter seperated so then I can reference it like AlphabetTbl[1] for substitution but I do not know how to find the letters in the text and turn them into a number so if it was a it would be one because AlphabetTbl[1] = "a" and so on and I am very confused and need help.
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","y","x","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 String = "cf"
local Match = function(letter)
for a,alp in pairs(Alphabet) do
if letter == alp then
return a
end
end
end
local Convert = function(Str) local convertedtable = {} local convertedstring = "" local Split = string.split(Str,"") for i,letter in pairs(Split) do local index = Match(letter) table.insert(convertedtable,i,index) convertedstring = convertedstring..(tostring(index)) end return convertedtable,convertedstring end
local Reverse = function(Number) local convertedtable = {} local convertedstring = "" local Str = tostring(Number) local Split = string.split(Str,"") for i,letter in pairs(Split) do table.insert(convertedtable,i,Alphabet[tonumber(letter)]) convertedstring = convertedstring..Alphabet[tonumber(letter)] end return convertedtable,convertedstring end
local reversetable,reversestring = Reverse(36) -- reversestring prints: cf local ctable,ctring = Convert(String)