SHARE
TWEET

Untitled

a guest Dec 31st, 2018 37 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local term = require("term")
  2. local component = require("component")
  3. local event = require("event")
  4. local m = component.modem
  5. local str="0"
  6.  
  7. -- determine what channel people want to listen on
  8. term.write("What channel do you want to chat on? \n")
  9. local channel=io.read()
  10. m.open(tonumber(channel))
  11. -- begin event
  12. event.listen("modem_message", function(_,_,from,port,_,message)
  13.  
  14. -- decipher, and print
  15. local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
  16. local function decrypt(str)
  17.         str = str:gsub("%d",function(a) return string.char(cipher:find(a,nil,true)+47) end)
  18.         str = str:gsub("%l",function(a) return string.char(cipher:find(a,nil,true)+86) end)
  19.         return str
  20. end
  21. if string.sub(tostring(message), 1, 9)=="encrypted" then
  22. str=tostring(message)
  23. message=decrypt(str)
  24. local strlngth=string.len(tostring(message))
  25. message=string.sub(tostring(message), 10, strlngth)
  26. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  27.  
  28. else
  29. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  30. end
  31. end)
  32.  
  33. -- send a message
  34. term.write("is this going to be encrypted? \n")
  35.  
  36. -- register cipher
  37. local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
  38.  
  39. local function encrypt(str)
  40.   str = str:gsub("%d",function(a) a=a:byte()-47 return cipher:sub(a,a) end)
  41.   str = str:gsub("%l",function(a) a=a:byte()-86 return cipher:sub(a,a) end)
  42.   return str
  43. end
  44. -- determine whether encryption should be used
  45. local useEC=io.read()
  46. if useEC=="yes" then
  47.   term.write("Encryption activated \n")
  48. end
  49. while true do
  50.   str=io.read()
  51.   if tostring(str)=="endme" then
  52.     os.exit()
  53.   end
  54.   if useEC=="yes" then
  55.     str=encrypt(str)
  56.     str="encrypted" .. " " .. str
  57.   end
  58. -- send message
  59. m.broadcast(tonumber(channel), str)
  60. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top