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=tostring(message)
- message=decrypt(str)
- local strlngth=string.len(tostring(message))
- message=string.sub(tostring(message), 10, strlngth)
- 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)
- local doEnd="0"
- -- allow users to exit the program
- local function GetEnder(_,_,keyCode,_,)
- if tostring(keyCode)=="0x1C" then
- os.exit()
- end
- end
- event.listen("key_down", GetEnder(_,_,keyCode,_,))
- -- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement