-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstring_encode.lua
More file actions
54 lines (48 loc) · 1.26 KB
/
string_encode.lua
File metadata and controls
54 lines (48 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- require binary/pull
-- require binary/itb
-- require binary/bits_to
-- require table/concat
-- require string/index_of
-- require string/string_rle
-- require string/string_rld
local encoding = '=abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()[]{}<>./;"\\|`~-_+'
function bits_to_string(bits)
local string = ''
while(#bits > 0) do
local id = pull(bits,6)+1
string = string..sub(encoding,id,id)
end
-- print('run length encoding...')
return string_rle(string)
end
-- function bytes_to_string(bytes)
-- local string = ''
-- local bits = {}
-- for byte in all(bytes) do
-- add(bits, itb(byte,8))
-- if(#bits >= 6) then
-- local id = pull(bits,6)+1
-- string = string..sub(encoding,id,id)
-- end
-- end
-- local id = pull(bits,6)+1
-- string = string..sub(encoding,id,id)
-- print('run length encoding...')
-- return string_rle(string)
-- end
function bits_from_string(string)
local bits = {}
for i, char in characters(string_rld(string)) do
concat(bits, itb(index_of(char, encoding)-1, 6))
end
return bits
end
function expand(size,table)
for k,v in pairs(table) do
table[k] = bits_to(size, bits_from_string(v))
end
return table
end
-- expect bits_to_string
-- expect bits_from_string
-- expect expand