Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - local term = require("term")
 - local component = require("component")
 - local event = require("event")
 - local m = component.modem
 - local str="0"
 - local userfile = "/home/.uname.txt"
 - local fs = require("filesystem")
 - local uname = fs.exists(userfile)
 - -- determine what channel people want to listen on
 - term.clear()
 - if uname then
 - local handler = fs.open(userfile)
 - user = handler:read(16)
 - handler:close()
 - else
 - term.write("You do not have a user profile. \n")
 - term.write("Please enter a 16 character user name: ")
 - local handler = fs.open(userfile, "w")
 - handler:write(io.read())
 - local handler = fs.open(userfile)
 - user = handler:read(16)
 - term.write("\n Username set to " .. user .. ". \n")
 - handler:close()
 - end
 - term.write("What channel do you want to chat on: ")
 - 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(tostring(message))
 - else
 - print(tostring(message))
 - end
 - end)
 - -- send a message
 - term.write("is this going to be encrypted? (yes/no) \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.clear()
 - term.write("Encryption activated \n")
 - sleep(5)
 - term.clear()
 - end
 - while true do
 - str= user .. ": " .. io.read()
 - if tostring(str)== user .. ": " .. "endme" then
 - term.clear()
 - event.ignore("modem_message", function(_,_,from,port,_,message)
 - os.exit()
 - end
 - if useEC=="yes" then
 - str= user .. ": " .. encrypt(str)
 - str="encrypted" .. " " .. str
 - end
 - -- send message
 - m.broadcast(tonumber(channel), str)
 - end
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment