Advertisement
VlaD00m

sdcreate.lua

Sep 1st, 2020
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.85 KB | None | 0 0
  1. --[[ SecuDrive Creator.
  2. Program for creating EEPROM-Floppy or EEPROM-Computronics tape pair for using in key-based access computer system
  3. Author: Bs()Dd
  4.  
  5. Requirements to computer system:
  6.  - Tier 1 Computer
  7.  - Tier 1 Processor
  8.  - 1x Tier 1 Memory
  9.  - Tier 1 Redstone Card or Redstone I/O block
  10.  - Floppy drive or Computronics streamer
  11.  - Computronics Colorful lamp (access indicator, optionally)
  12. ]]
  13.  
  14. component = require('component')
  15.  
  16. local function confirm(msg)
  17.     print(msg)
  18.     print("Type `y` to write, `s` to skip (if medium already written).")
  19.     repeat
  20.       local response = io.read()
  21.       if response and response:lower():sub(1, 1) == "s" then
  22.         return false
  23.       end
  24.     until response and response:lower():sub(1, 1) == "y"
  25.   return true
  26. end
  27.  
  28. print('SecuDrive Creator v1.1')
  29. print('2020 (c) Compys Security Software\n')
  30. print('What type of key will be use (floppy, tape): ')
  31. repeat
  32.        response = io.read()
  33.     until response == "floppy" or response == "tape"
  34. print('Enter number side for correct code signal (0-5): ')
  35. repeat
  36.        corr = tonumber(io.read())
  37.     until corr < 6 and corr > -1
  38. print('Enter number side for incorrect code signal (0-5): ')
  39. repeat
  40.        inco = tonumber(io.read())
  41.     until inco < 6 and inco > -1
  42. print('Enter password code: ')    
  43.  local passw = io.read()  
  44. if response == "tape" then
  45.    if confirm("\nInsert EEPROM in computer\nOLD DATA WILL BE ERASED!") then
  46.      local chip = component.eeprom
  47.      chip.set(string.format('local function lamp(colcode)\nllist = component.list("colorful_lamp")()\nif llist ~= nil then\nldev = component.proxy(llist)\nif colcode == 0 then ldev.setLampColor(25368) end\nif colcode == 1 then ldev.setLampColor(512) end\nif colcode == 2 then ldev.setLampColor(16384) end\nend\nend\ndrive = component.proxy(component.list("tape_drive")())\nred = component.proxy(component.list("redstone")())\ncode = "%s"\nincorr= %s\ncorr= %s\nwhile true do\nif drive.isReady() then\ndrive.seek(-drive.getSize())\ntcode = drive.read(#code)\nwhile drive.isReady() == true do\nif code == tcode then\nred.setOutput(corr, 15)\nred.setOutput(incorr, 0)\nlamp(1)\nelse\nred.setOutput(incorr, 15)\nred.setOutput(corr, 0)\nlamp(2)\nend\nend\nelse\nred.setOutput(corr, 0)\nred.setOutput(incorr, 0)\nlamp(0)\nend\nend', passw, inco, corr))
  48.      chip.setLabel('SecuDrive Tape BIOS')
  49.      print('OK!\n')
  50.    end
  51.    if confirm("Insert tape in streamer\nOLD DATA WILL BE ERASED!") then
  52.      local tape = component.tape_drive
  53.      tape.stop()
  54.      tape.seek(-tape.getSize())
  55.      tape.stop()
  56.      tape.write(passw)
  57.      tape.stop()
  58.      tape.seek(-tape.getSize())
  59.      tape.stop()
  60.      print('OK!\n')
  61.      print("Enter new label for tape. Leave input blank to leave the label unchanged.")
  62.      label = io.read()
  63.      if label and #label > 0 then
  64.        tape.setLabel(label)
  65.        print('')
  66.      end
  67.    end
  68.    print('SecuDrive components successfully created!')
  69. end
  70. if response == "floppy" then
  71.   if confirm("\nInsert EEPROM in computer\nOLD DATA WILL BE ERASED!") then
  72.      local chip = component.eeprom
  73.      chip.set(string.format('red = component.proxy(component.list("redstone")())\ndrive = component.proxy(component.list("disk_drive")())\ncode = "%s"\nincorr= %s \ncorr= %s\nlocal function lamp(colcode)\nllist = component.list("colorful_lamp")()\nif llist ~= nil then\nldev = component.proxy(llist)\nif colcode == 0 then ldev.setLampColor(25368) end\nif colcode == 1 then ldev.setLampColor(512) end\nif colcode == 2 then ldev.setLampColor(16384) end\nend\nend\nwhile true do\nif not drive.isEmpty() then\nfloppy = component.proxy(drive.media())\nif floppy.readByte ~= nil then\nlocal curs = 0\nlocal discode = ""\nwhile curs ~= #code do\ndiscode = discode .. string.char(floppy.readByte(curs+1))\ncurs = curs + 1\nend\nwhile not drive.isEmpty() do\nif code == discode then\nred.setOutput(corr, 15)\nred.setOutput(incorr, 0)\nlamp(1)\nelse\nred.setOutput(incorr, 15)\nred.setOutput(corr, 0)\nlamp(2)\nend\nend\nelse\nwhile not drive.isEmpty() do\nred.setOutput(incorr, 15)\nred.setOutput(corr, 0)\nlamp(2)\nend\nend\nelse\nwhile drive.isEmpty() do\nred.setOutput(corr, 0)\nred.setOutput(incorr, 0)\nlamp(0)\nend\nend\nend', passw, inco, corr))
  74.      chip.setLabel('SecuDrive Floppy BIOS')
  75.      print('OK!\n')
  76.    end
  77.    if confirm("Turn floppy to UNMANAGED MODE and insert in drive\nOLD DATA WILL BE ERASED!") then
  78.      local floppy = component.proxy(component.disk_drive.media())
  79.      local curs = 0
  80.      while curs ~= #passw do
  81.         floppy.writeByte(curs+1, string.byte(passw:sub(curs+1,curs+1)))
  82.         curs = curs + 1
  83.      end
  84.      print('OK!\n')
  85.      print("Enter new label for floppy. Leave input blank to leave the label unchanged.")
  86.      label = io.read()
  87.      if label and #label > 0 then
  88.        floppy.setLabel(label)
  89.        print('')
  90.      end
  91.    end
  92.    print('SecuDrive components successfully created!')
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement