Advertisement
DOGGYWOOF

Untitled

Jul 16th, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. -- Function to decrypt text using a key
  2. function decrypt(text, key)
  3. local map = invertMap(createMap(key))
  4. local decrypted = {}
  5. for i = 1, #text do
  6. local char = text:sub(i, i)
  7. table.insert(decrypted, map[char] or char)
  8. end
  9. return table.concat(decrypted)
  10. end
  11.  
  12. -- Function to load the key from a file and check if decryption is possible
  13. function checkAndDecrypt()
  14. local rootFiles = fs.list("/")
  15. local keyFile = nil
  16.  
  17. -- Check for key file in the root directory
  18. for _, file in ipairs(rootFiles) do
  19. if string.match(file, "^key%d+%.txt$") then
  20. keyFile = file
  21. break
  22. end
  23. end
  24.  
  25. if keyFile then
  26. showProtectionScreen(keyFile)
  27. else
  28. print("No encryption key found. Use 'encrypt' mode to encrypt files.")
  29. end
  30. end
  31.  
  32. -- Function to show protection screen options
  33. function showProtectionScreen(keyFile)
  34. term.clear()
  35. term.setCursorPos(1, 1)
  36. print("Doggy OS File System Protection")
  37. print()
  38. print("F1 - Unlock")
  39. print("F8 - Shutdown")
  40. print("F9 - Recover System")
  41.  
  42. while true do
  43. local event, key = os.pullEvent("key")
  44. if key == keys.f1 then
  45. local key = loadKeyFromFile(keyFile)
  46. processDirectory("/disk", decrypt, key)
  47. shell.run("/disk/boot/start-check")
  48. return
  49. elseif key == keys.f8 then
  50. os.shutdown()
  51. return
  52. elseif key == keys.f9 then
  53. recoverSystem()
  54. return
  55. end
  56. end
  57. end
  58.  
  59. -- Function to recover the system (delete disk and replace with recovery)
  60. function recoverSystem()
  61. local files = fs.list("/disk")
  62. for _, file in ipairs(files) do
  63. local filePath = fs.combine("/disk", file)
  64. if not fs.isDir(filePath) then
  65. fs.delete(filePath)
  66. end
  67. end
  68. -- Optionally copy recovery files from a backup location or setup
  69. print("System recovered. Please restart your system.")
  70. end
  71.  
  72. -- Main Program
  73. term.clear()
  74. term.setCursorPos(1, 1)
  75. print("Doggy OS File System Encryption")
  76. print()
  77. print("Initializing...")
  78.  
  79. local tArgs = {...}
  80. local mode = tArgs[1]
  81.  
  82. if mode == "encrypt" then
  83. local key = generateKey()
  84. encryptDirectory("/disk", key)
  85. local keyFileName = saveKeyToFile(key)
  86. print("All files in /disk/ encrypted.")
  87. print("Key saved to file: " .. keyFileName)
  88. print()
  89. print("Encryption complete.")
  90. else
  91. print("Doggy OS File System Protection")
  92. print()
  93. checkAndDecrypt()
  94. end
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement