Guest User

Multiple Encryption 1

a guest
Feb 26th, 2013
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local function enc(str, key)
  2.     if not key then return false end
  3.     local f = ""
  4.     local kb = {}
  5.     for i = 1, #key do
  6.         kb[i] = string.byte(key:sub(i,i)) - 31
  7.     end
  8.     local c = 1
  9.     for i = 1, #str do
  10.         local t1 = string.byte(str:sub(i,i))
  11.         if t1 == 10 then
  12.             f = f .. string.char(10)
  13.         else
  14.             local t2 = t1 + kb[c]
  15.             if t2 > 126 then
  16.                 local t3 = t2 - 126
  17.                 t2 = 31 + t3
  18.             end
  19.         f = f .. string.char(t2)
  20.         end
  21.         c = c + 1
  22.         if c > #key then
  23.             c = 1
  24.         end
  25.     end
  26.     return f
  27. end
  28.  
  29. local function dec(str, key)
  30.     if not key then return false end
  31.     local f = ""
  32.     local kb = {}
  33.     for i = 1, #key do
  34.         kb[i] = string.byte(key:sub(i,i)) - 31
  35.     end
  36.     local c = 1
  37.     for i = 1, #str do
  38.         local t2 = string.byte(str:sub(i,i)) - 31
  39.         if t2 == -21 then
  40.             f = f .. string.char(10)
  41.         else
  42.             local t3 = t2 - kb[c] + 31
  43.             if t3 < 32 then
  44.                 t3 = t3 + 126 - 31
  45.             end
  46.             if t3 < 32 then return false, t3 end
  47.             if t3 > 126 then return false, t3 end
  48.             f = f .. string.char(t3)
  49.         end
  50.         c = c + 1
  51.         if c > #key then
  52.             c = 1
  53.         end
  54.     end
  55.     return f
  56. end
  57.  
  58. function encrypt(str, key)
  59.     if not key then return false end
  60.     if #key < 3 then return false end
  61.     local f = str
  62.     key = key .. key .. "#me1"
  63.     for i = 0, #key - 1 do
  64.         f = enc(f, key:sub(i,i + 1))
  65.     end
  66.     f = enc(f, key:sub(1,2) .. key:sub(#key - 1, #key) .. enc(key, key .. key))
  67.     return f
  68. end
  69.  
  70. function decrypt(str, key)
  71.     if not key then return false end
  72.     if #key < 3 then return false end
  73.     local f = str
  74.     key = key .. key .. "#me1"
  75.     for i = 0, #key - 1 do
  76.         f = dec(f, key:sub(i,i + 1))
  77.     end
  78.     f = dec(f, key:sub(1,2) .. key:sub(#key - 1, #key) .. enc(key, key .. key))
  79.     return f
  80. end
Advertisement
Add Comment
Please, Sign In to add comment