tiin57

cipher_adv

Sep 12th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. local function split(self, sep)
  2.     local sep, fields = sep or ":", {}
  3.     local pattern = string.format("([^%s]+)", sep)
  4.     self:gsub(pattern, function(c) fields[#fields+1]=c end)
  5.     return fields
  6. end
  7.  
  8. function encode(text, scrambler)
  9.     if not scrambler then
  10.         scrambler="There's no scrambler"
  11.     end
  12.     local chars = {}
  13.     for i=1, #text do
  14.         chars[i]=text:sub(i, i)
  15.     end
  16.     key = math.random(10000, 99999)
  17.     for i=1, #scrambler do
  18.         key=key+string.byte(scrambler:sub(i, i))
  19.     end
  20.     local coded=""
  21.     for _, v in pairs(chars) do
  22.         coded=coded..":"..tostring(string.byte(v)*key)
  23.     end
  24.     return coded:sub(2), key
  25. end
  26.  
  27. function decode(text, key)
  28.     numbers = split(text, ":")
  29.     final = ""
  30.     for _, v in pairs(numbers) do
  31.         if tonumber(v)==nil then break end
  32.         final=final..string.char(tonumber(v)/key)
  33.     end
  34.     return final
  35. end
Advertisement
Add Comment
Please, Sign In to add comment