Page 1 of 1

rot13 script

Posted: Mon Mar 19, 2018 1:32 pm
by Oreolek
A rot13 ASCII alias command (actually, it's rot-anything):

Code: Select all

<regex>^rot(\d+) (.*)</regex>
<script>
local KEY = matches[2]
local line = matches[3]

function Rotate(t)
  return (string.gsub(t, "[%a]",
    function (char)
      local bUpper = (char < 'a')
      local b = string.byte(string.upper(char)) - 65 -- 0 to 25
      b = math.mod(b + KEY, 26)
      if bUpper then
        return string.char(b + 65)
      else
        return string.char(b + 97)
      end
    end
  ))
end

echo(Rotate(line).."\n")
</script>