23 posts
Posted 22 June 2012 - 05:21 AM
I have a question, is it possible to read the letters in something a user inputted and change them? For example; say a user inputted "Hello" could the computer use variables set as something such as a = n b = o (rot13, I would use a complete set to translate every letter back and forth) and make a coder/decoder? So that "Hello" could be resent to the user as "Uryyb"?
351 posts
Posted 22 June 2012 - 02:44 PM
Look up string.byte and string.char in the docs. Also this is like the fifth thread about this topic in a few days… what is going on?
134 posts
Location
Salt Lake, UT
Posted 22 June 2012 - 02:55 PM
1604 posts
Posted 22 June 2012 - 03:59 PM
Well, it's really easy to do it with the string api and a table:
-- table with each character
local t = {
["a"] = "n",
["b"] = "o",
...
}
-- get the user input
local input = read()
local msg = ""
-- loop through every character
for char in string.gmatch(input, ".") do
-- get the character
local c = t[char] or char
-- add it to the message
msg = msg..c
end
-- now use msg for whatever you want
351 posts
Posted 22 June 2012 - 04:08 PM
The parts you skip over with comments are significant. I am pretty sure byte and char are a better solution in almost every case.
1604 posts
Posted 22 June 2012 - 04:39 PM
The parts you skip over with comments are significant. I am pretty sure byte and char are a better solution in almost every case.
How much more detail do you want? If you (or anyone else) want to know how the functions work, you can look at them in the lua manual.
Also, how would string.byte and string.char help here?