Advertisement
programcreator

Door Lock Server

Feb 6th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. dofile = function(path,...)
  2.     local f = loadfile(path)
  3.     setfenv(f,_G)
  4.     return f(...)
  5. end
  6.  
  7. local Tunnel = dofile("Tunnel/init.lua","Tunnel")
  8. local AESkeys = {}
  9.  
  10. local file = fs.open("pass","r")
  11. local pass = file.readAll()
  12. print(pass)
  13. file.close()
  14.  
  15. local modem = peripheral.wrap("right")
  16.  
  17. modem.open(405)
  18.  
  19. local function addConnection()
  20.     while true do
  21.         print("Adding connection...")
  22.         local secretNumber = Tunnel.DH.connect(modem,404,BigNum)
  23.         local AESkey = Tunnel.SHA.sha256(tostring(secretNumber))
  24.         local id = #AESkeys + 1
  25.         AESkeys[id] = AESkey
  26.         modem.transmit(404,2,id)
  27.     end
  28. end
  29.  
  30. term.redirect(term.native())
  31.  
  32. local event = {}
  33.  
  34. local function main()
  35.     while true do
  36.         event = {os.pullEvent()}
  37.         if event[1] == "modem_message" and event[3] == 405 then
  38.         decrypted = nil
  39.             local decrypted = Tunnel.AES.decryptBytes(AESkeys[event[4]],event[5])
  40.             if decrypted == pass then
  41.                 print("WOW, Yissss!")
  42.                 rs.setOutput("left",true)
  43.                 sleep(3)
  44.                 rs.setOutput("left",false)
  45.             end
  46.         end
  47.     end
  48. end
  49.  
  50. parallel.waitForAll(main,addConnection)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement