Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- pastebin run 0DUyWTFc
- --]]
- --API made by valithor.
- local encrypt = function(msg,key)
- local num = ""
- for i = 1, #key do
- local let = key:sub(i,i):byte()
- num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
- num = #msg..num
- end
- math.randomseed(tonumber(num))
- local encrypt = ""
- for i = 1, #msg do
- local rotation = math.random(0,94)
- local byte = msg:sub(i,i):byte()
- local rotate = rotation+byte <= 127 and rotation +byte or ((rotation+byte)%127)+32
- encrypt = encrypt..string.char(rotate)
- end
- return encrypt
- end
- local fixstr = function(str)
- return str:gsub(string.char(9)," ")
- end
- local yield = function()
- os.queueEvent("yield")
- os.pullEvent("yield")
- end
- local decrypt = function(msg,key)
- local num = ""
- for i = 1, #key do
- local let = key:sub(i,i):byte()
- num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
- num = #msg..num
- end
- math.randomseed(tonumber(num))
- local decrypt = ""
- for i = 1, #msg do
- local rotation = math.random(0,94)
- local byte = msg:sub(i,i):byte()
- local rotate = byte-rotation >= 32 and byte-rotation or byte-rotation
- if rotate < 32 then
- rotate = rotate+95
- end
- decrypt = decrypt..string.char(rotate)
- end
- return decrypt
- end
- local tEnc = function(msg,key)
- return encrypt(tostring(msg),key)
- end
- local tDec = function(msg,key)
- return decrypt(tostring(msg),key)
- end
- listAll = function(_path, _files, noredundant, excludeFiles)
- local thisProgram = ""
- if shell then
- thisProgram = shell.getRunningProgram()
- end
- local path = _path or ""
- local files = _files or {}
- if #path > 1 then table.insert(files, path) end
- for _, file in ipairs(fs.list(path)) do
- local path = fs.combine(path, file)
- if (file ~= thisProgram) and (not fs.isReadOnly(file)) then
- local guud = true
- for a = 1, #excludeFiles do
- if excludeFiles[a] == file then
- guud = false
- break
- end
- end
- if guud then
- if fs.isDir(path) then
- listAll(path, files, noredundant, excludeFiles)
- else
- table.insert(files, path)
- end
- end
- end
- end
- if noredundant then
- for a = 1, #files do
- if fs.isDir(tostring(files[a])) then
- if #fs.list(tostring(files[a])) ~= 0 then
- table.remove(files,a)
- end
- end
- end
- end
- return files
- end
- local function choice(input,visual)
- if visual then
- write("[")
- for a = 1, input:len() do
- write(input:sub(a,a):upper())
- if a ~= input:len() then write(",") end
- end
- write("]?")
- end
- local event, button
- repeat
- event, button = os.pullEvent("key")
- if type(button) == "number" then button = keys.getName(button) end
- if button == nil then button = " " end
- until string.find(input, button)
- if visual then
- print(button:upper())
- end
- return button, true
- end
- local getEncAll = function(encOrDec,kee,_paath,exclude)
- local paath = _paath or ""
- local contents
- local filetree = {}
- local filelist = listAll(paath,nil,true,exclude)
- for a = 1, #filelist do
- local isDir
- contents = {}
- if not fs.isDir(filelist[a]) then
- local file = fs.open(filelist[a],"r")
- local line = ""
- local s = 0
- while line do
- line = file.readLine()
- if line then
- if encOrDec == "e" then
- table.insert(contents,tEnc(fixstr(line),kee))
- else
- table.insert(contents,tDec(fixstr(line),kee))
- end
- if s >= 64 then
- yield()
- s = 0
- else
- s = s + 1
- end
- end
- end
- file.close()
- isDir = false
- else
- contents = {""}
- isDir = true
- end
- filetree[filelist[a]] = {fyle = contents, dir = isDir}
- end
- return filetree
- end
- doCrypting = function(mode,key,path,exclude)
- if mode ~= "e" and mode ~= "d" then
- error("mode should be 'e' or 'd'")
- end
- key = key or "password"
- path = path or ""
- local amnt = 0
- local encedFiles = getEncAll(mode,key,path,exclude)
- for k,v in pairs(encedFiles) do
- amnt = amnt + 1
- if not v.dir then
- if not fs.getDir(k) then fs.makeDir(fs.getDir(k)) end
- local file = fs.open(k,"w")
- file.write(table.concat(v.fyle,"\n"))
- file.close()
- else
- fs.makeDir(k)
- end
- end
- return amnt, mode
- end
- if shell then --if not being used as an API
- sleep(0)
- print("Encrypt or decrypt?")
- local ency = choice("ed",true)
- print("\nWhat path?")
- write("/")
- sleep(0)
- local doPath = read()
- print("\nEnter key:")
- write(":")
- sleep(0)
- local enckey = read("*")
- if ency == "e" then
- print("Encrypting...")
- else
- print("Decrypting...")
- end
- doCrypting(ency,enckey,doPath,{shell.getRunningProgram()})
- print("Done!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement