Advertisement
Doob

lol

Jul 10th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. local str = 'absclkdallskd'
  2. local d, e = {}, {}
  3.  
  4. local function transform(s, st, border, s_len, b_len, c)
  5.   local stream, result, i = '', '', 1
  6.   while i <= #s do
  7.     local a, b = ''
  8.     if st then -- if decoding
  9.       b = string.byte(e[s:sub(i,i)])
  10.     else -- if encoding
  11.       b = s:sub(i,i):byte()
  12.     end
  13.     for o = 0, border do
  14.       a = bit32.extract(b, o)..a
  15.     end
  16.     stream = stream..a
  17.     if #stream == s_len then
  18.       for j = 1, #stream, b_len do
  19.         result = result..string.char(tonumber(stream:sub(j, j+c),2))
  20.       end
  21.       stream = ''
  22.     end
  23.     s, i = s:sub(2), i-1
  24.   end
  25.   return result
  26. end
  27.  
  28. local function encode()
  29.   for i = 1, #str do
  30.     local o = str:sub(i,i)
  31.     if not d[o] then
  32.       d[o] = true
  33.     end
  34.   end
  35.   for i in pairs(d) do
  36.     table.insert(e, i)
  37.   end
  38.   d = nil
  39.   table.sort(e,function(a,b)if a:byte()<b:byte()then return true else return false end end)
  40.  
  41.   if #e > 128 then
  42.     return nil
  43.   elseif #e <= 128 and #e >= 65 then -- 7
  44.     if string.byte(e[#e]) <= 127 then -- standart
  45.       print(#e, '7s')
  46.     else -- adaptive
  47.       print(#e, '7a')
  48.     end
  49.   elseif #e <= 64 and #e >= 33 then -- 6
  50.     print(#e, '6a')
  51.   elseif #e <= 32 and #e >= 17 then -- 5
  52.     print(#e, '5a')
  53.   elseif #e <= 16 then -- 4
  54.     print(#e, '4a')
  55.   end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement