Advertisement
Bolodefchoco_LUAXML

[String] string.rotate

Feb 7th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 07/02/2016
  3. --Last update: 27/11/2016
  4. --[[ Notes:
  5.     Does:
  6.         Gera os próximos unicodes de str para rotation bytes a frente
  7.     Args:
  8.         str --> String
  9.         rotation --> Número para rotacionar a string
  10.         lettersOnly --> Caso true, unicodes além de letras serão ignorados na rotação
  11. ]]--
  12.  
  13. string.rotate = function(str,rotation,lettersOnly)
  14.     if lettersOnly then
  15.         local b,c
  16.         local newStr = {}
  17.         for i = 1,#str do
  18.             b = str:sub(i,i):byte()
  19.             c = (b > 96 and b < 123) and 97 or (b > 64 and b < 91) and 65 or false
  20.             if c then
  21.                 newStr[#newStr + 1] = string.char((c + (((b - c) + rotation) % 26)))
  22.             end
  23.         end
  24.         return table.concat(newStr)
  25.     else
  26.         str = str:gsub("(.)",function(c)
  27.             return string.char(c:byte() + rotation)
  28.         end)
  29.         return str
  30.     end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement