#!Lua-5.0.exe -- ROT-13 text. -- http://en.wikipedia.org/wiki/Rot13 -- by Philippe Lhoste http://Phi.Lho.free.fr -- v. 1.1 -- 2004/10/22 -- A more elegant algorithm, inspired by Roberto's one -- v. 1.0 -- 2004/10/21 -- Creation local text = "This article have been written on April first!" -- Old code, all mine! function Rotate13(t) return (string.gsub(t, "[%u%l]", function (char) local bUpper = (char < 'a') local b = string.byte(string.upper(char)) - 65 -- 0 to 25 b = math.mod(b + 13, 26) if bUpper then return string.char(b + 65) else return string.char(b + 97) end end )) end -- New code, more concise and more elegant (not relying on numerical codes). function Rotate13(t) local byte_a, byte_A = string.byte('a'), string.byte('A') return (string.gsub(t, "[%a]", function (char) local offset = (char < 'a') and byte_A or byte_a local b = string.byte(char) - offset -- 0 to 25 b = math.mod(b + 13, 26) + offset -- Rotate return string.char(b) end )) end print(Rotate13(text))