Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("modem")
- modem.open(1234)
- local pass = "testme"
- local shift = 6
- local isServer = true
- function makeTable(tbl,chr)
- local num = string.byte(chr)
- local cur_size = #tbl
- for i=1,8 do
- local n_val = 0
- if (num % 2) == 1 then
- n_val = 1
- num = num -1
- end
- num = num / 2
- tbl[cur_size+9-i] = n_val
- end
- return tbl
- end
- function dequeue(bit_table)
- if #bit_table == 0 then
- if bit_table.txt == "" then
- return
- end
- local chr = bit_table.txt:sub(1,1)
- bit_table.txt = bit_table.txt:sub(2)
- makeTable(bit_table,chr)
- end
- local val = bit_table[1]
- for i=1,#bit_table do
- bit_table[i] = bit_table[i+1]
- end
- return val
- end
- function dequeueChar(bit_table)
- local num = 0
- for i=1,8 do
- num = num * 2
- local tmp = dequeue(bit_table)
- if not tmp then return end
- num = num + tmp
- end
- return string.char(num)
- end
- function makeTest(pass)
- local bit_table = {}
- for i=1,shift do
- bit_table[i] = math.random(0,1)
- end
- bit_table.txt = pass
- local msg = ""
- while true do
- local tmp = dequeueChar(bit_table)
- if not tmp then break end
- msg = msg..tmp
- end
- return msg
- end
- function test(msg)
- local bit_table = {}
- bit_table.txt = msg
- for i=1,shift do
- dequeue(bit_table)
- end
- local tmp = pass
- for i=1,#tmp do
- if tmp:sub(i,i) ~= dequeueChar(bit_table) then
- return false
- end
- end
- return true
- end
- if isServer then
- while true do
- local evt,sd,c1,c2,msg = os.pullEvent("modem_message")
- if test(msg) then
- redstone.setOutput(side,not redstone.getOutput(side))
- end
- end
- else
- modem.transmit(1234,1234,makeTest(read()))
- end
- --print(test(makeTest()))
Advertisement
Add Comment
Please, Sign In to add comment