Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- DO NOT USE
- -- ENCODE-ONLY
- if not fs.exists"bignum"then local a=http.get"https://raw.githubusercontent.com/ennorehling/euler/master/BigNum.lua"local b=fs.open("bignum","w")b.write(a.readAll())a.close()b.close()end
- -- this is ported from https://github.com/qntm/base1/blob/master/index.js
- -- use the comments there
- dofile "bignum"
- local base = BigNum.new(256)
- local base1 = {}
- local function yield()
- os.queueEvent "dummy"
- os.pullEvent "dummy"
- end
- function base1.encodeL(bin)
- local len = #bin
- local out = BigNum.new(0)
- -- Integerise binary data
- for i = 1, len do
- local val = string.byte(bin:sub(i, i))
- out = (out * base) + val
- yield()
- end
- local binlength = 0
- local blocksize = base ^ BigNum.new(binlength)
- while binlength < len do
- out = out + blocksize
- blocksize = blocksize * base
- binlength = binlength + 1
- yield()
- end
- return out
- end
- function base1.decodeL(l)
- local binlength = 0
- local blocksize = base ^ BigNum.new(binlength)
- while l <= blocksize do
- l = l - blocksize
- blocksize = blocksize * base
- binlength = binlength + 1
- end
- local out = ""
- local byte = binlength - 1
- while byte >= 0 do
- end
- end
- print(base1.encodeL "hi")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement