Guest User

enc

a guest
Apr 12th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1.  
  2. local function tostr(bts)
  3.   local str = ""
  4.   for k, v in pairs(bts) do
  5.     if type(v) == "number" then
  6.       str = str..string.char(v)
  7.     end
  8.   end
  9.   return str
  10. end
  11. local function tobits(str)
  12.   local rtrntbl = {}
  13.   for char in string.gmatch(str, ".") do
  14.     rtrntbl[#rtrntbl+1] = string.byte(char)
  15.   end
  16.   return rtrntbl
  17. end
  18. local function mkKey(key)
  19.   local key = tostring(key)
  20.   local str = ""
  21.   for char in string.gmatch(key, ".") do
  22.     str = str..tostring(string.byte(char))
  23.   end
  24.   return str
  25. end
  26. local function sepkey(key)
  27.   local key = tostring(key)
  28.   local ky = {}
  29.   for char in string.gmatch(key, ".") do
  30.     ky[#ky+1] = tonumber(char)
  31.   end
  32.   return ky
  33. end
  34. local function enc(keyo, str1)
  35.   local str2 = tobits(str1)
  36.   local key = sepkey(mkKey(keyo))
  37.   local num = 0
  38.   for k, v in pairs(str2) do
  39.     num = num+1
  40.     if num > #key then
  41.       num = 1
  42.     end
  43.     if v+key[num] > 255 then
  44.       str2[k] = v+key[num]-255
  45.     else
  46.       str2[k] = v+key[num]
  47.     end
  48.   end
  49.   str2 = tostr(str2)
  50.   return str2
  51. end
  52. function encrypt(key, str)
  53.   local keyn = sepkey(mkKey(key))
  54.   keyn = keyn[#keyn-1]
  55.   local rtrn
  56.   local cnt = 0
  57.   for i = 1, string.byte(keyn) do
  58.     cnt = cnt+1
  59.     rtrn = enc(key, str)
  60.     if cnt == 100 then
  61.       cnt = 0
  62.       sleep(0)
  63.     end
  64.   end
  65.   return rtrn
  66. end
  67. local function dec(keyo, str1)
  68.   local str2 = tobits(str1)
  69.   local key = sepkey(mkKey(keyo))
  70.   local num = 0
  71.   for k, v in pairs(str2) do
  72.     num = num+1
  73.     if num > #key then
  74.       num = 1
  75.     end
  76.     if v+key[num] < 0 then
  77.       str2[k] = v-key[num]+255
  78.     else
  79.       str2[k] = v-key[num]
  80.     end
  81.   end
  82.   str2 = tostr(str2)
  83.   return str2
  84. end
  85. function decrypt(key, str)
  86.   local keyn = sepkey(mkKey(key))
  87.   keyn = keyn[#keyn-1]
  88.   local rtrn
  89.   local cnt = 0
  90.   for i = 1, string.byte(keyn) do
  91.     cnt = cnt+1
  92.     rtrn = dec(key, str)
  93.     if cnt == 100 then
  94.       cnt = 0
  95.       sleep(0)
  96.     end
  97.   end
  98.   return rtrn
  99. end
Add Comment
Please, Sign In to add comment