Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term = require("term")
- local fs = require("filesystem")
- local component = require("component")
- local event = require("event")
- local m = component.modem
- local str="0"
- -- determine what channel people want to listen on
- term.write("What channel do you want to chat on? \n")
- local channel=io.read()
- m.open(tonumber(channel))
- -- begin event
- event.listen("modem_message", function(_,_,from,port,_,message)
- -- decipher, and print
- local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
- local function decrypt(str)
- str = str:gsub("%d",function(a) return string.char(cipher:find(a,nil,true)+47) end)
- str = str:gsub("%l",function(a) return string.char(cipher:find(a,nil,true)+86) end)
- return str
- end
- if string.sub(tostring(message), 1, 9)=="encrypted" then
- str=tosring(message)
- message=decrypt(str)
- print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
- else
- print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
- end
- end)
- repeat
- -- send a message
- term.write("is this going to be encrypted? \n")
- -- register cipher
- local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
- local function encrypt(str)
- str = str:gsub("%d",function(a) a=a:byte()-47 return cipher:sub(a,a) end)
- str = str:gsub("%l",function(a) a=a:byte()-86 return cipher:sub(a,a) end)
- return str
- end
- -- determine whether encryption should be used
- local useEC=io.read()
- if useEC=="yes" then
- term.write("Encryption activated")
- str=io.read()
- str=encrypt(str)
- str="encrypted" .. " " .. str
- else
- str=io.read()
- end
- -- open
- m.broadcast(tonumber(channel), str)
- fs.copy("/data/usr/programs/networkSendTest.lua", "/mnt/34d/networkSendTest.lua")
- print("Do you want to continue?")
- -- determine whether to continue or not
- local decision=io.read()
- until tostring(decision)=="no" or tostring(decision)=="close"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement