Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The program that creates the MUID of the current computer.
- -- (c) ProgramCrafter
- local function BitStream()
- local t = {}
- local readv = function(start, len)
- local v = 0
- for i = start, start + len - 1 do
- v = v * 2 + (t[i] or 0)
- end
- return v
- end
- local bitstream = {
- extend = function(len, value)
- local st = #t
- for i = 1, len do
- t[st + i] = value or 0
- end
- end,
- put = function(...)
- local st = #t
- for i = 1, table.pack(...).n do
- t[st + i] = select(i, ...) or 0
- end
- end,
- hexdigest = function()
- local s = '0123456789ABCDEF'
- local k = {}
- for i = 1, #t, 4 do
- local v = readv(i, 4) + 1
- k[#k + 1] = s:sub(v, v)
- end
- return table.concat(k, '')
- end,
- b64digest = function()
- local s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
- local k = {}
- for i = 1, #t, 6 do
- local v = readv(i, 6) + 1
- k[#k + 1] = s:sub(v, v)
- end
- return table.concat(k, '')
- end
- }
- return bitstream
- end
- local hex = {
- ['0'] = {0, 0, 0, 0},
- ['1'] = {0, 0, 0, 1},
- ['2'] = {0, 0, 1, 0},
- ['3'] = {0, 0, 1, 1},
- ['4'] = {0, 1, 0, 0},
- ['5'] = {0, 1, 0, 1},
- ['6'] = {0, 1, 1, 0},
- ['7'] = {0, 1, 1, 1},
- ['8'] = {1, 0, 0, 0},
- ['9'] = {1, 0, 0, 1},
- ['A'] = {1, 0, 1, 0},
- ['B'] = {1, 0, 1, 1},
- ['C'] = {1, 1, 0, 0},
- ['D'] = {1, 1, 0, 1},
- ['E'] = {1, 1, 1, 0},
- ['F'] = {1, 1, 1, 1},
- }
- local function getTimeDelta(bitstream)
- error('NotImplementedError')
- end
- local function getIP(bitstream)
- error('NotImplementedError')
- end
- local function getOCVersion(bitstream)
- local v = _OSVERSION:sub(10, 10)
- if hex[v] then bitstream.put(table.unpack(hex[v])) end
- end
- local function getLuVersion(bitstream)
- local v = _VERSION:sub(7, 7)
- if v == '2' then bitstream.put(0)
- else bitstream.put(1) end
- end
- local function compAddress(bitstream)
- local com = require 'component'
- local s = com.computer.address:upper()
- for i = 1, #s do
- if hex[s:sub(i, i)] then bitstream.put(table.unpack(hex[s:sub(i, i)])) end
- end
- end
- local function eeprAddress(bitstream)
- local com = require 'component'
- local s = com.eeprom.address:upper()
- for i = 1, #s do
- if hex[s:sub(i, i)] then bitstream.put(table.unpack(hex[s:sub(i, i)])) end
- end
- end
- local function eeprData(bitstream)
- local com = require 'component'
- local s = com.eeprom.getData():upper()
- local j = 0
- for i = 1, #s do
- if hex[s:sub(i, i)] then
- bitstream.put(table.unpack(hex[s:sub(i, i)]))
- j = j + 1
- if j == 32 then return end
- end
- end
- end
- local function getConnection(bitstream)
- bitstream.put(0, 0, 0, 0)
- end
- local function getAveragePing(bitstream)
- bitstream.extend(7)
- end
- local function sessionRandom(bitstream)
- for i = 1, 128 do
- bitstream.put((math.random() > 0.5) and 1 or 0)
- end
- end
- local function sessionTemp(bitstream)
- local fs = require 'filesystem'
- local s = fs.findNode('/tmp').fs.address:upper()
- for i = 1, #s do
- if hex[s:sub(i, i)] then bitstream.put(table.unpack(hex[s:sub(i, i)])) end
- end
- end
- local function safeGetInfo(fnn, fn, bitstream, alt_length)
- local success, reason = pcall(fn, bitstream)
- if success then return end
- bitstream.extend(alt_length, 0)
- end
- local bs = BitStream()
- safeGetInfo('TimeDelta', getTimeDelta, bs, 14)
- safeGetInfo('IP', getIP, bs, 32)
- safeGetInfo('OCVersion', getOCVersion, bs, 4)
- safeGetInfo('LuVersion', getLuVersion, bs, 1)
- safeGetInfo('CompAddress', compAddress, bs, 128)
- safeGetInfo('EeprAddress', eeprAddress, bs, 128)
- safeGetInfo('BootAddress', eeprData, bs, 128)
- safeGetInfo('Connection', getConnection, bs, 4)
- safeGetInfo('ConnPING', getAveragePing, bs, 7)
- safeGetInfo('SessRAND', sessionRandom, bs, 128)
- safeGetInfo('SessTEMP', sessionTemp, bs, 128)
- _G.digest = bs.b64digest()
Add Comment
Please, Sign In to add comment