Advertisement
DOGGYWOOF

Untitled

Aug 27th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. -- User authentication and decryption program with UI
  2.  
  3. local function xorEncryptDecrypt(data, key)
  4. local result = ""
  5. for i = 1, #data do
  6. result = result .. string.char(bit.bxor(data:byte(i), key))
  7. end
  8. return result
  9. end
  10.  
  11. local function drawUI()
  12. term.clear()
  13. term.setCursorPos(1, 1)
  14. print("========================================")
  15. print(" Doggy OS Administrator File System")
  16. print(" Protection API v1.0")
  17. print("========================================")
  18. end
  19.  
  20. local function authenticateUser()
  21. drawUI()
  22. print("Enter username:")
  23. local username = read()
  24. drawUI()
  25. print("Enter password:")
  26. local password = read("*") -- Masked input for password
  27.  
  28. local userPath = "/disk/users/" .. username .. "/password.txt"
  29. if not fs.exists(userPath) then
  30. drawUI()
  31. print("User does not exist.")
  32. sleep(2)
  33. return false
  34. end
  35.  
  36. local fileHandle = fs.open(userPath, "r")
  37. local storedPassword = fileHandle.readAll()
  38. fileHandle.close()
  39.  
  40. local decryptedPassword = xorEncryptDecrypt(storedPassword, 123)
  41. if password == decryptedPassword then
  42. local adminFilePath = "/disk/users/" .. username .. "/admin.txt"
  43. if fs.exists(adminFilePath) then
  44. return true
  45. else
  46. drawUI()
  47. print("User is not an admin.")
  48. sleep(2)
  49. return false
  50. end
  51. else
  52. drawUI()
  53. print("Incorrect password.")
  54. sleep(2)
  55. return false
  56. end
  57. end
  58.  
  59. local function decryptDirectory(directory)
  60. local files = fs.list(directory)
  61. for _, file in ipairs(files) do
  62. local path = fs.combine(directory, file)
  63. if fs.isDir(path) then
  64. decryptDirectory(path)
  65. else
  66. local fileHandle = fs.open(path, "r")
  67. local content = fileHandle.readAll()
  68. fileHandle.close()
  69. local decryptedContent = xorEncryptDecrypt(content, 123)
  70. fileHandle = fs.open(path, "w")
  71. fileHandle.write(decryptedContent)
  72. fileHandle.close()
  73. print("Decrypted: " .. path)
  74. end
  75. end
  76. end
  77.  
  78. -- Main program
  79. drawUI()
  80. print("Welcome to Doggy OS Administrator File System Protection API.")
  81. sleep(2)
  82. if authenticateUser() then
  83. drawUI()
  84. print("Authentication successful. Starting decryption...")
  85. decryptDirectory("/disk/")
  86. print("Decryption completed.")
  87. else
  88. drawUI()
  89. print("Authentication failed. Exiting.")
  90. end
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement