Advertisement
minimite

ccipher

Nov 1st, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.36 KB | None | 0 0
  1. function encrypt(text, key)
  2.     return text:gsub("%a", function(t)
  3.             local base = (t:lower() == t and string.byte('a') or string.byte('A'))
  4.  
  5.             local r = t:byte() - base
  6.             r = r + key
  7.             r = r%26 -- works correctly even if r is negative
  8.             r = r + base
  9.             return string.char(r)
  10.         end)
  11. end
  12.  
  13. function decrypt(text, key)
  14.     return encrypt(text, -key)
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement