Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- User authentication and decryption program with UI
- local function xorEncryptDecrypt(data, key)
- local result = ""
- for i = 1, #data do
- result = result .. string.char(bit.bxor(data:byte(i), key))
- end
- return result
- end
- local function drawUI()
- term.clear()
- term.setCursorPos(1, 1)
- print("========================================")
- print(" Doggy OS Administrator File System")
- print(" Protection API v1.0")
- print("========================================")
- end
- local function authenticateUser()
- drawUI()
- print("Enter username:")
- local username = read()
- drawUI()
- print("Enter password:")
- local password = read("*") -- Masked input for password
- local userPath = "/disk/users/" .. username .. "/password.txt"
- if not fs.exists(userPath) then
- drawUI()
- print("User does not exist.")
- sleep(2)
- return false
- end
- local fileHandle = fs.open(userPath, "r")
- local storedPassword = fileHandle.readAll()
- fileHandle.close()
- local decryptedPassword = xorEncryptDecrypt(storedPassword, 123)
- if password == decryptedPassword then
- local adminFilePath = "/disk/users/" .. username .. "/admin.txt"
- if fs.exists(adminFilePath) then
- return true
- else
- drawUI()
- print("User is not an admin.")
- sleep(2)
- return false
- end
- else
- drawUI()
- print("Incorrect password.")
- sleep(2)
- return false
- end
- end
- local function decryptDirectory(directory)
- local files = fs.list(directory)
- for _, file in ipairs(files) do
- local path = fs.combine(directory, file)
- if fs.isDir(path) then
- decryptDirectory(path)
- else
- local fileHandle = fs.open(path, "r")
- local content = fileHandle.readAll()
- fileHandle.close()
- local decryptedContent = xorEncryptDecrypt(content, 123)
- fileHandle = fs.open(path, "w")
- fileHandle.write(decryptedContent)
- fileHandle.close()
- print("Decrypted: " .. path)
- end
- end
- end
- -- Main program
- drawUI()
- print("Welcome to Doggy OS Administrator File System Protection API.")
- sleep(2)
- if authenticateUser() then
- drawUI()
- print("Authentication successful. Starting decryption...")
- decryptDirectory("/disk/")
- print("Decryption completed.")
- else
- drawUI()
- print("Authentication failed. Exiting.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement