loadedCryptoPath = null
crypto = include_lib("/lib/crypto.so")
if crypto then
loadedCryptoPath = "/lib/crypto.so"
else
localCryptoPath = parent_path(program_path) + "/crypto.so"
crypto = include_lib(localCryptoPath)
if not crypto then exit("<color=#f00>crypto not found</color>")
loadedCryptoPath = localCryptoPath
end if
selfPath = program_path
// Additional files to ignore
extraSkipPaths = [
selfPath,
loadedCryptoPath,
"/bin/ls",
"/bin/cd",
"/bin/cat"
]
doneCount = 0
failCount = 0
skipCount = 0
askChoice = function(tries)
if tries >= 3 then
return null
end if
print("")
print("1. Encrypt")
print("2. Decrypt")
answer = user_input("Choice (1/2): ")
if answer == "1" then return "1"
if answer == "2" then return "2"
print("Invalid choice.")
return askChoice(tries + 1)
end function
pathInSkipList = function(path, skipList)
if not path then return 0
if typeof(skipList) != "list" then return 0
for p in skipList
if path == p then
return 1
end if
end for
return 0
end function
shouldSkip = function(path)
if not path then return 1
if pathInSkipList(path, extraSkipPaths) == 1 then
return 1
end if
return 0
end function
processFile = function(f, mode, pass)
if not f then
return
end if
if f.is_folder == 1 then
return
end if
if shouldSkip(f.path) == 1 then
print("[SKIP] " + f.path)
globals.skipCount = globals.skipCount + 1
return
end if
result = null
if mode == "1" then
result = crypto.encrypt(f.path, pass)
else
result = crypto.decrypt(f.path, pass)
end if
if result == 1 then
print("[OK] " + f.path)
globals.doneCount = globals.doneCount + 1
else
print("[ERR] " + f.path + " -> " + result)
globals.failCount = globals.failCount + 1
end if
end function
walkFolder = function(folder, mode, pass)
if not folder then
return
end if
if folder.is_folder != 1 then
processFile(folder, mode, pass)
return
end if
files = folder.get_files
if typeof(files) == "list" then
for f in files
processFile(f, mode, pass)
end for
end if
folders = folder.get_folders
if typeof(folders) == "list" then
for sub in folders
walkFolder(sub, mode, pass)
end for
end if
end function
choice = askChoice(0)
if not choice then
exit("Cancelled.")
end if
targetPath = user_input("Target file or folder: ")
if targetPath == "" then
exit("No target provided.")
end if
password = user_input("Password: ", 1)
if password == "" then
exit("Empty password.")
end if
comp = get_shell.host_computer
target = comp.File(targetPath)
if not target then
exit("Target not found: " + targetPath)
end if
walkFolder(target, choice, password)
if choice == "1" then
lockResult = target.chmod("o-wrx", 1)
if lockResult == "" then
print("[LOCK] 'Others' permissions removed.")
else
print("[LOCK ERR] " + lockResult)
end if
end if
print("")
print("Program used : " + selfPath)
print("Crypto library : " + loadedCryptoPath)
print("Finished.")
print("OK : " + globals.doneCount)
print("FAIL : " + globals.failCount)
print("SKIP : " + globals.skipCount)