Advertisement
Guest User

Untitled

a guest
May 12th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. local term = require("term")
  2. local fs = require("filesystem")
  3. local component = require("component")
  4. local event = require("event")
  5. local m = component.modem
  6. local str="0"
  7.  
  8. -- determine what channel people want to listen on
  9. term.write("What channel do you want to chat on? \n")
  10. local channel=io.read()
  11. m.open(tonumber(channel))
  12. -- begin event
  13. event.listen("modem_message", function(_,_,from,port,_,message)
  14.  
  15. local doEnd="0"
  16. -- allow users to exit the program
  17. local function GetEnder(doEnd)
  18. If tostring(doEnd)=="endme" then
  19. os.exit()
  20. end
  21. end
  22. event.listen("key_down", doEnd(
  23. -- decipher, and print
  24. local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
  25. local function decrypt(str)
  26. str = str:gsub("%d",function(a) return string.char(cipher:find(a,nil,true)+47) end)
  27. str = str:gsub("%l",function(a) return string.char(cipher:find(a,nil,true)+86) end)
  28. return str
  29. end
  30. if string.sub(tostring(message), 1, 9)=="encrypted" then
  31. str=tostring(message)
  32. message=decrypt(str)
  33. local strlngth=string.len(tostring(message))
  34. message=string.sub(tostring(message), 10, strlngth)
  35. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  36.  
  37. else
  38. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  39. end
  40. end)
  41.  
  42. -- send a message
  43. term.write("is this going to be encrypted? \n")
  44.  
  45. -- register cipher
  46. local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
  47.  
  48. local function encrypt(str)
  49. str = str:gsub("%d",function(a) a=a:byte()-47 return cipher:sub(a,a) end)
  50. str = str:gsub("%l",function(a) a=a:byte()-86 return cipher:sub(a,a) end)
  51. return str
  52. end
  53. -- determine whether encryption should be used
  54. local useEC=io.read()
  55. if useEC=="yes" then
  56. term.write("Encryption activated \n")
  57. end
  58. while true do
  59. if useEC=="yes" then
  60. str=io.read()
  61. str=encrypt(str)
  62. str="encrypted" .. " " .. str
  63. else
  64. str=io.read()
  65. end
  66. -- send message
  67. m.broadcast(tonumber(channel), str)
  68. fs.copy("/data/usr/programs/networkSendTest.lua", "/mnt/34d/networkSendTest.lua")
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement