Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- I, didn't create the api so I don't take any merit for it. I post it because I use it in my programms I think it is extremely well written.
- local function enc(str, key)
- if not key then return false end
- local f = ""
- local kb = {}
- for i = 1, #key do
- kb[i] = string.byte(key:sub(i,i)) - 31
- end
- local c = 1
- for i = 1, #str do
- local t1 = string.byte(str:sub(i,i))
- if t1 == 10 then
- f = f .. string.char(10)
- else
- local t2 = t1 + kb[c]
- if t2 > 126 then
- local t3 = t2 - 126
- t2 = 31 + t3
- end
- f = f .. string.char(t2)
- end
- c = c + 1
- if c > #key then
- c = 1
- end
- end
- return f
- end
- local function dec(str, key)
- if not key then return false end
- local f = ""
- local kb = {}
- for i = 1, #key do
- kb[i] = string.byte(key:sub(i,i)) - 31
- end
- local c = 1
- for i = 1, #str do
- local t2 = string.byte(str:sub(i,i)) - 31
- if t2 == -21 then
- f = f .. string.char(10)
- else
- local t3 = t2 - kb[c] + 31
- if t3 < 32 then
- t3 = t3 + 126 - 31
- end
- if t3 < 32 then return false, t3 end
- if t3 > 126 then return false, t3 end
- f = f .. string.char(t3)
- end
- c = c + 1
- if c > #key then
- c = 1
- end
- end
- return f
- end
- function encrypt(str, key)
- if not key then return false end
- if #key < 3 then return false end
- local f = str
- key = key .. key .. "#me1"
- for i = 0, #key - 1 do
- f = enc(f, key:sub(i,i + 1))
- end
- f = enc(f, key:sub(1,2) .. key:sub(#key - 1, #key) .. enc(key, key .. key))
- return f
- end
- function decrypt(str, key)
- if not key then return false end
- if #key < 3 then return false end
- local f = str
- key = key .. key .. "#me1"
- for i = 0, #key - 1 do
- f = dec(f, key:sub(i,i + 1))
- end
- f = dec(f, key:sub(1,2) .. key:sub(#key - 1, #key) .. enc(key, key .. key))
- return f
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement