Advertisement
k2green

Key

Jun 21st, 2025 (edited)
454
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 1
  1. local args = { ... }
  2.  
  3. if not fs.exists("aes.lua") then
  4.     shell.run("wget", "https://gist.githubusercontent.com/LolloDev5123/9409c11864934a7f08c7a7d65295ddad/raw/5b93d8ed7156ad81b21abda1d1fba4a34a5730c9/AES.lua", "aes.lua")
  5. end
  6.  
  7. if not fs.exists("encode.lua") then
  8.     shell.run("pastebin", "get", "ksk0HmaJ", "encode.lua")
  9. end
  10.  
  11. local aes = require("aes")
  12. local encode = require("encode")
  13.  
  14. local function encode(bytes)
  15.     return string.char(table.unpack(bytes))
  16. end
  17.  
  18. local function findDisk()
  19.     local periphs = peripheral.getNames()
  20.     for k,v in ipairs(periphs) do
  21.         local type = peripheral.getType(v)
  22.         if type == "drive" then
  23.             return true, v
  24.         end
  25.     end
  26.  
  27.     return false
  28. end
  29.  
  30. local function run()
  31.     if args[1] == "create" then
  32.         local diskFound, name = findDisk()
  33.         if not diskFound then
  34.             print("A disk drive must be attached to use this feature")
  35.             return
  36.         end
  37.  
  38.         if not disk.isPresent(name) then
  39.             print("A disk must be inserted into the disk drive")
  40.             return
  41.         end
  42.  
  43.         disk.setLabel(name, "Encryption Key")
  44.  
  45.         local mountPath = disk.getMountPath(name)
  46.         local key = aes.GenerateRandomKey()
  47.         local encoded = encode(key)
  48.  
  49.         local file = fs.open(mountPath .. "/key.txt", "w")
  50.         file.write(encoded)
  51.         file.close()
  52.  
  53.         print("Created key on disk")
  54.     end
  55. end
  56.  
  57. run()
Tags: Key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement