Advertisement
Guest User

Untitled

a guest
May 12th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 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. -- 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=tosring(message)
  23. message=decrypt(str)
  24. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  25.  
  26. else
  27. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  28. end
  29. end)
  30. repeat
  31. -- send a message
  32. term.write("is this going to be encrypted? \n")
  33.  
  34. -- register cipher
  35. local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
  36.  
  37. local function encrypt(str)
  38. str = str:gsub("%d",function(a) a=a:byte()-47 return cipher:sub(a,a) end)
  39. str = str:gsub("%l",function(a) a=a:byte()-86 return cipher:sub(a,a) end)
  40. return str
  41. end
  42. -- determine whether encryption should be used
  43. local useEC=io.read()
  44.  
  45. if useEC=="yes" then
  46. term.write("Encryption activated")
  47. str=io.read()
  48. str=encrypt(str)
  49. str="encrypted" .. " " .. str
  50. else
  51. str=io.read()
  52. end
  53. -- open
  54. m.broadcast(tonumber(channel), str)
  55. fs.copy("/data/usr/programs/networkSendTest.lua", "/mnt/34d/networkSendTest.lua")
  56. print("Do you want to continue?")
  57. -- determine whether to continue or not
  58.  
  59. local decision=io.read()
  60. until tostring(decision)=="no" or tostring(decision)=="close"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement