KrYn0MoRe

bits and bytes mumbo jumbo system

Oct 3rd, 2020 (edited)
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. local bits = 8 -- minimum 8 bits for all string characters to load
  2. local starting_char = 0 -- 97 for only letters, 0 for all characters
  3. local reserve = bits
  4.  
  5. function get_size(n)
  6.     local kb = 1000
  7.     local mb = kb*1000
  8.     local gb = mb*1000
  9.     local tb = gb*1000
  10.     local t = ''
  11.     local c = false
  12.     if n >= tb then
  13.         repeat
  14.             n = n/tb;
  15.             t = 'tb';
  16.         until tb > n
  17.     elseif n >= gb then
  18.         repeat
  19.             n = n/gb;
  20.             t = 'gb';
  21.         until gb > n
  22.     elseif n >= mb then
  23.         repeat
  24.             n = n/mb;
  25.             t = 'mb';
  26.         until mb > n
  27.     elseif n >= kb then
  28.         repeat
  29.             n = n/kb;
  30.             t = 'kb';
  31.         until kb > n
  32.     else
  33.         c = true
  34.         t = 'byte'
  35.     end
  36.     if not c then
  37.         n = n-(n%0.01)
  38.     end
  39.     t = tostring(n) .. ' ' .. t
  40.     return t
  41. end
  42.  
  43. function make_byte(char)
  44.     local byte = {}
  45.     local indentity = string.byte(char)-starting_char
  46.     --print(indentity)
  47.     for i = 1,reserve,1 do
  48.         local p = 2^(reserve-i)
  49.         local r = 0
  50.         if indentity >= p then
  51.             indentity -= p
  52.             r += 1
  53.         end
  54.         byte[2^(reserve-i)] = r
  55.     end
  56.     return byte
  57. end
  58.  
  59. function convert_string_to_bytes(str)
  60.     local _time = tick()
  61.     local bytes = {}
  62.     local s = ''
  63.     for i = 1, string.len(str) do
  64.         bytes[i] = make_byte(string.sub(str,i,i))
  65.         for bit = #bytes[i],1,-1 do
  66.             if bytes[i][bit] then
  67.                 s = s .. bytes[i][bit]
  68.             end
  69.         end
  70.         s = s .. ' '
  71.     end
  72.     return bytes,_time,s
  73. end
  74.  
  75. function convert_bytes_to_string(bytes,_time)
  76.     local s = ''
  77.     for i = 1,#bytes do
  78.         local n = 0
  79.         for place,bit in pairs(bytes[i]) do
  80.             local p = 2^(reserve)
  81.             if bytes[i][place] >= 1 then
  82.                 n += place
  83.             end
  84.         end
  85.         n = n+starting_char
  86.         s = s .. string.char(n)
  87.     end
  88.     return bytes,s,tick()-_time
  89. end
  90.  
  91. local char = owner.Character
  92. local head = char['Head']
  93.  
  94. BillboardGui0 = Instance.new("BillboardGui")
  95. TextBox1 = Instance.new("TextBox")
  96. BillboardGui0.Parent = head
  97. BillboardGui0.LightInfluence = 1
  98. BillboardGui0.Size = UDim2.new(8, 0, 3, 0)
  99. BillboardGui0.Active = true
  100. BillboardGui0.ClipsDescendants = true
  101. BillboardGui0.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  102. BillboardGui0.SizeOffset = Vector2.new(0, 2)
  103. TextBox1.Parent = BillboardGui0
  104. TextBox1.Size = UDim2.new(1, 0, 1, 0)
  105. TextBox1.BackgroundColor = BrickColor.new("Institutional white")
  106. TextBox1.BackgroundColor3 = Color3.new(1, 1, 1)
  107. TextBox1.BackgroundTransparency = 1
  108. TextBox1.Font = Enum.Font.SourceSans
  109. TextBox1.FontSize = Enum.FontSize.Size14
  110. TextBox1.TextColor = BrickColor.new("Institutional white")
  111. TextBox1.TextColor3 = Color3.new(1, 1, 1)
  112. TextBox1.TextScaled = true
  113. TextBox1.TextSize = 14
  114. TextBox1.TextStrokeTransparency = 0
  115. TextBox1.TextWrap = true
  116. TextBox1.TextWrapped = true
  117.  
  118. function changetxt(str)
  119.     local c = {convert_string_to_bytes(str)}
  120.     local bytes,str2,_time = convert_bytes_to_string(unpack(c))
  121.     TextBox1.Text = 'co: ' .. c[3] .. '\n de: ' .. str2 .. '\n bytes: ' .. get_size(table.getn(bytes)) .. '\n time: ' .. _time-(_time%0.001)
  122. end
  123.  
  124. owner.Chatted:Connect(function(msg)
  125.     if msg:lower():sub(1,4) == 'con/' then
  126.         local str = msg:sub(5)
  127.         if str then
  128.             changetxt(str)
  129.         end
  130.     elseif msg:lower():sub(1,7) == '/e con/' then
  131.         local str = msg:sub(8)
  132.         if str then
  133.             changetxt(str)
  134.         end
  135.     elseif msg:lower():sub(1,5) == 'crep/' then
  136.         local str = msg:sub(6)
  137.         if str then
  138.             changetxt(string.rep(str,100))
  139.         end
  140.     elseif msg:lower():sub(1,8) == '/e crep/' then
  141.         local str = msg:sub(9)
  142.         if str then
  143.             changetxt(string.rep(str,100))
  144.         end
  145.     end
  146. end)
Add Comment
Please, Sign In to add comment