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.73 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. -- decipher, and print
  16. local cipher = "1234567890qwertyuiopasdfghjklzxcvbnm"
  17. local function decrypt(str)
  18. str = str:gsub("%d",function(a) return string.char(cipher:find(a,nil,true)+47) end)
  19. str = str:gsub("%l",function(a) return string.char(cipher:find(a,nil,true)+86) end)
  20. return str
  21. end
  22. if string.sub(tostring(message), 1, 9)=="encrypted" then
  23. str=tostring(message)
  24. message=decrypt(str)
  25. local strlngth=string.len(tostring(message))
  26. message=string.sub(tostring(message), 10, strlngth)
  27. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  28.  
  29. else
  30. print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
  31. end
  32. end)
  33. local doEnd="0"
  34. -- allow users to exit the program
  35. local function GetEnder(_,_,keyCode,_,)
  36. if tostring(keyCode)=="0x1C" then
  37. os.exit()
  38. end
  39. end
  40. event.listen("key_down", GetEnder(_,_,keyCode,_,))
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement