Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local inputs = {...}
- list = {
- [0] = "0",
- [1] = "1",
- [2] = "2",
- [3] = "3",
- [4] = "4",
- [5] = "5",
- [6] = "6",
- [7] = "7",
- [8] = "8",
- [9] = "9",
- [10] = "A",
- [11] = "B",
- [12] = "C",
- [13] = "D",
- [14] = "E",
- [15] = "F"
- }
- function tostring(b)
- s = ''
- s = s .. list[math.floor(b/16)]
- s = s .. list[b % 16]
- return s;
- end
- bytes = {
- ['0'] = 0,
- ['1'] = 1,
- ["2"] = 2,
- ["3"] = 3,
- ["4"] = 4,
- ["5"] = 5,
- ["6"] = 6,
- ["7"] = 7,
- ["8"] = 8,
- ["9"] = 9,
- ["A"] = 10,
- ["B"] = 11,
- ['C'] = 12,
- ["D"] = 13,
- ["E"] = 14,
- ["F"] = 15
- }
- path = inputs[1]
- if fs.exists(path) then
- if inputs[2] == "pack" then
- file = fs.open(path, "rb")
- str = ""
- b = file.read()
- i = 0
- while b ~= nil do
- str = str .. tostring(b)
- b = file.read()
- i = i + 1
- end
- file.close()
- bytesLen = i-1
- file = fs.open("pack", "w")
- file.writeLine(str)
- file.close()
- end
- if inputs[2] == "unpack" then
- file = fs.open(path, "r")
- str = file.readLine(str)
- file.close()
- file = fs.open("unpack", "wb")
- i = 1
- s = string.sub(str, i , i)
- len = string.len(str)
- while s ~= nil do
- if i < len then
- num = bytes[s]
- i = i + 1
- s = string.sub(str, i , i)
- num = num*16 + bytes[s]
- file.write(num);
- i = i + 1
- s = string.sub(str, i , i)
- else s = nil
- end
- end
- file.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement