Advertisement
DOGGYWOOF

Untitled

Aug 27th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. -- Encryption program
  2.  
  3. local key = 123 -- Define a simple key for XOR encryption
  4.  
  5. -- Function to encrypt/decrypt a string using XOR
  6. local function xorEncryptDecrypt(data, key)
  7. local result = ""
  8. for i = 1, #data do
  9. result = result .. string.char(bit.bxor(data:byte(i), key))
  10. end
  11. return result
  12. end
  13.  
  14. -- Function to encrypt all files in a directory
  15. local function encryptDirectory(directory)
  16. local files = fs.list(directory)
  17. for _, file in ipairs(files) do
  18. local path = fs.combine(directory, file)
  19. if fs.isDir(path) then
  20. -- Recursively encrypt directories
  21. encryptDirectory(path)
  22. else
  23. local fileHandle = fs.open(path, "r")
  24. local content = fileHandle.readAll()
  25. fileHandle.close()
  26. local encryptedContent = xorEncryptDecrypt(content, key)
  27. fileHandle = fs.open(path, "w")
  28. fileHandle.write(encryptedContent)
  29. fileHandle.close()
  30. print("Encrypted: " .. path)
  31. end
  32. end
  33. end
  34.  
  35. -- Start encryption
  36. encryptDirectory("/disk/")
  37. print("Encryption completed.")
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement