KrYn0MoRe

delta encoder and decoder

Oct 10th, 2020 (edited)
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. function delta_encode(str)
  2.     local delta = ''
  3.     local last = 0
  4.     for i = 1,string.len(str) do
  5.         local n = string.byte(string.sub(str,i,i))
  6.         delta = delta .. string.byte(string.sub(str,i,i))-last .. ' '
  7.         last = n
  8.     end
  9.     delta = string.sub(delta,1,string.len(delta)-1)
  10.     return delta
  11. end
  12.  
  13. function delta_decode(delta)
  14.     local sdelta = string.split(delta,' ')
  15.     local last = sdelta[1]
  16.     local str = string.char(last)
  17.     for i = 2,#sdelta do
  18.         local n = tonumber(sdelta[i])
  19.         last = last+n
  20.         str = str .. string.char(last)
  21.     end
  22.     return str
  23. end
  24.  
  25. local char = owner.Character
  26. local head = char['Head']
  27.  
  28. BillboardGui0 = Instance.new("BillboardGui")
  29. TextBox1 = Instance.new("TextBox")
  30. BillboardGui0.Parent = head
  31. BillboardGui0.LightInfluence = 1
  32. BillboardGui0.Size = UDim2.new(8, 0, 3, 0)
  33. BillboardGui0.Active = true
  34. BillboardGui0.ClipsDescendants = true
  35. BillboardGui0.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  36. BillboardGui0.SizeOffset = Vector2.new(0, 2)
  37. TextBox1.Parent = BillboardGui0
  38. TextBox1.Size = UDim2.new(1, 0, 1, 0)
  39. TextBox1.BackgroundColor = BrickColor.new("Institutional white")
  40. TextBox1.BackgroundColor3 = Color3.new(1, 1, 1)
  41. TextBox1.BackgroundTransparency = 1
  42. TextBox1.Font = Enum.Font.SourceSans
  43. TextBox1.FontSize = Enum.FontSize.Size14
  44. TextBox1.TextColor = BrickColor.new("Institutional white")
  45. TextBox1.TextColor3 = Color3.new(1, 1, 1)
  46. TextBox1.TextScaled = true
  47. TextBox1.TextSize = 14
  48. TextBox1.TextStrokeTransparency = 0
  49. TextBox1.TextWrap = true
  50. TextBox1.TextWrapped = true
  51.  
  52. function test(str)
  53.     local d = delta_encode(str)
  54.     local s = delta_decode(d)
  55.     TextBox1.Text = 'encoded: ' .. d .. '\n decoded: ' .. s
  56. end
  57.  
  58. owner.Chatted:Connect(function(msg)
  59.     if msg:lower():sub(1,4) == 'enc/' then
  60.         local str = msg:sub(5)
  61.         if str then
  62.             test(str)
  63.         end
  64.     elseif msg:lower():sub(1,7) == '/e enc/' then
  65.         local str = msg:sub(8)
  66.         if str then
  67.             test(str)
  68.         end
  69.     end
  70. end)
Add Comment
Please, Sign In to add comment