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

Help making a cipher for a puzzle game?

Asked by 4 years ago

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.

0
Do you mean the printed thing is like 'a = 1, b = 2' of an example? Xapelize 2658 — 4y
0
No I want the encrypt function to turn a string like "abcdefghijklmnopqrstuvwxyz" to 123456789 and so on but I can add the serpator I just need help with the conversion Nescients 2 — 4y

1 answer

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
4 years ago
Edited 4 years ago

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)

0
Decided to sapre some time so here it is if you have any questions feel free to ask! karlo_tr10 1233 — 4y
0
How would you reverse this and undo it? Nescients 2 — 4y
0
I updated the answer, it now has reverse function that does that. karlo_tr10 1233 — 4y
Ad

Answer this question