Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Encryption v2 --
- --[[
- Because this is something dealing with security, I will not be putting as many notes in here compaired to my other programs because people might
- be able to see how it works faster by looking at them. This does not mean that I will not be putting notes in here though, just not as many.
- This program creates a duplicate version of the files that are modified following the extention "_encry" and "_decry" depending on if you
- decrypted or encrypted the files. Names of files inside of folders will not be renamed, only the folder containing the files.
- As said I don't take any responsibility for any files or folder lost using this program.
- ]]
- -- pre-functions
- function clr() return term.clear() end
- function cp(x,y) return term.setCursorPos(x,y) end
- function setText(col) if term.isColor() then return term.setTextColor(colors[col]) end end
- function setBack(col) if term.isColor() then return term.setBackgroundColor(colors[col]) end end
- function notnil(vari) if vari == nil then return false else return true end end
- -- pre-functions
- -- pre-values --
- w,h = term.getSize() -- gets size of computer (entire computer, not the window api)
- local running = true
- term.setCursorBlink(true)
- -- pre-values --
- -- main functions --
- local function _save(fil,info)
- local file_info = {}
- local file = fs.open(fil, "w")
- local cnt = 0
- for i=1, #info do
- cnt = cnt + 1
- file.writeLine(info[i])
- if cnt == 200 then
- sleep(.000001)
- cnt = 0
- end
- end file.close() return true
- end
- local function _load(fil)
- local file_info = {}
- local file = fs.open(fil, "r")
- local tmp = ""
- local cnt = 0
- repeat
- cnt = cnt + 1
- tmp = file.readLine()
- if notnil(tmp) then
- table.insert(file_info, tmp)
- end
- if cnt == 200 then
- sleep(.000001)
- cnt = 0
- end
- until not notnil(tmp) file.close() return file_info
- end
- local old = term.current()
- local wind = window.create(term.current(), 1,1,w,h-2)
- local first_display = true
- local function console(text,warn)
- local oldTerm = term.redirect(wind)
- if first_display then first_display = false print("Console v.1.0-ED-2020") print("Created by Just Does Games") end
- if notnil(warn) then if warn then setText("orange") else setText("red") end else setText("gray") end
- print("") if not notnil(console_display) then write("[Console]") end setText("white")
- local toggle = 0
- for i=1, string.len(text) do
- write(string.sub(text,i,i))
- if string.sub(text,i,i) == ":" then
- setText("yellow")
- end
- if toggle == 10 then
- toggle = 0
- if not notnil(instant) then sleep(.000000001) end
- else
- toggle = toggle+1
- end
- end
- local newTerm = term.redirect(old)
- cp(1,h-1) term.clearLine() cp(1,h-1) setText("white") write("> ") term.setCursorBlink(true) if not notnil(instant) then sleep(.035) end
- end
- local function listAll(_path, _files)
- local path = _path or ""
- local files = _files or {}
- local loop = 0
- --if #path > 1 then table.insert(files, path) end
- for _, file in ipairs(fs.list(path)) do
- local path = fs.combine(path, file)
- if fs.isDir(path) then
- listAll(path, files)
- else
- table.insert(files, path)
- end
- loop = loop + 1
- if loop == 1000 then
- sleep(.1)
- loop = 0
- end
- end
- for i=1, #files do
- if fs.isDir(files[i]) then table.remove(files,i) end
- end
- return files
- end
- function encrypt(location, password)
- if type(password) ~= "string" then return error("password was not a string. got "..type(password)) end
- if type(location) ~= "string" then return error("location was not a string. got "..type(location)) end
- if not fs.exists(location) then return error("location does not exists. got "..location) end
- console("Running with password: "..password)
- console("Running with path: "..location)
- console("Creating coded password from password...")
- local pass = {}
- for i=1, string.len(password) do
- table.insert(pass, string.byte(string.sub(password,i,i)))
- end
- console("Password Decoded!")
- console("Loading file(s)...")
- file_info = {}
- local full_list = {}
- if fs.isDir(location) then
- full_list = listAll(location)
- for i=1, #full_list do
- table.insert(file_info, _load(full_list[i]))
- end
- else
- table.insert(full_list, location)
- table.insert(file_info, _load(location))
- end
- console("Total amount of files found: "..#full_list)
- console("Converting to code...")
- local byte_file_info = {}
- for i=1, #file_info do
- local loop = 0
- byte_file_info[i] = {}
- for ii=1, #file_info[i] do
- if string.len(file_info[i][ii]) == 0 then file_info[i][ii] = " " end
- --console("DEBUG: "..#file_info[i][ii])
- byte_file_info[i][ii] = {}
- for iii=1, string.len(file_info[i][ii]) do
- table.insert(byte_file_info[i][ii], string.byte(string.sub(file_info[i][ii],iii,iii)))
- end
- if loop == 1000 then
- loop = 0
- sleep(.1)
- else
- loop = loop + 1
- end
- end
- console("Loaded "..i.." out of "..#file_info..": "..math.floor((i/#file_info)*100).."%")
- end
- --error(#byte_file_info[1]) -- should return # of lines of this program
- console(#byte_file_info.." File(s) converted Successfully!", true)
- console("Encrypting "..#byte_file_info.." file(s)...")
- for i=1, #byte_file_info do -- repeats only twice
- local loop = 1
- local d_loop = 0
- for ii=1, #byte_file_info[i] do -- repeats 300+ times
- for iii=1, #byte_file_info[i][ii] do
- byte_file_info[i][ii][iii] = byte_file_info[i][ii][iii]+pass[loop]
- if byte_file_info[i][ii][iii] > 255 then
- byte_file_info[i][ii][iii] = byte_file_info[i][ii][iii]-255
- end
- loop = loop + 1
- if loop > #pass then
- loop = 1
- end
- end
- if d_loop == 1000 then
- d_loop = 0
- console(fs.getName(full_list[i])..": "..ii.."/"..#byte_file_info[i].." "..math.floor((ii/#byte_file_info[i])*10).."%")
- else
- d_loop = d_loop + 1
- end
- --console("Debug: "..i.."/"..ii)
- end
- console("Encrypted "..i.." out of "..#byte_file_info.." : "..math.floor((i/#byte_file_info)*100).."%") sleep(.1)
- end
- console("Encryption Done!",true)
- console("Saving file(s)...",true)
- --error(#byte_file_info[1])
- for i=1, #byte_file_info do
- local file = fs.open(string.gsub(location,"_decry","").."_encry/"..string.gsub(full_list[i],location,""), "w")
- if notnil(file) then
- for ii=1, #byte_file_info[i] do
- for iii=1, #byte_file_info[i][ii] do
- file.write(string.char(byte_file_info[i][ii][iii]))
- end
- file.writeLine("")
- end
- file.close()
- console("Saving: "..i.."/"..#byte_file_info.." "..math.floor((i/#byte_file_info)*100).."%")
- else
- console("Error saving to file, this can happen for many reasons.",false)
- end
- end
- console("Save Successfull! Done.",true)
- console("Thank you. Made by Just Does Games!") sleep(1)
- return true
- end
- function decrypt(location, password)
- if type(password) ~= "string" then return error("password was not a string. got "..type(password)) end
- if type(location) ~= "string" then return error("location was not a string. got "..type(location)) end
- if not fs.exists(location) then return error("location does not exists. got "..location) end
- console("Running with password: "..password)
- console("Running with path: "..location)
- console("Creating coded password from password...")
- local pass = {}
- for i=1, string.len(password) do
- table.insert(pass, string.byte(string.sub(password,i,i)))
- end
- console("Password Decoded!")
- console("Loading file(s)...")
- file_info = {}
- local full_list = {}
- if fs.isDir(location) then
- full_list = listAll(location)
- for i=1, #full_list do
- table.insert(file_info, _load(full_list[i]))
- end
- else
- table.insert(full_list, location)
- table.insert(file_info, _load(location))
- end
- console("Total amount of files found: "..#full_list)
- console("Converting to code...")
- local byte_file_info = {}
- for i=1, #file_info do
- local loop = 0
- byte_file_info[i] = {}
- for ii=1, #file_info[i] do
- if string.len(file_info[i][ii]) == 0 then file_info[i][ii] = " " end
- --console("DEBUG: "..#file_info[i][ii])
- byte_file_info[i][ii] = {}
- for iii=1, string.len(file_info[i][ii]) do
- table.insert(byte_file_info[i][ii], string.byte(string.sub(file_info[i][ii],iii,iii)))
- end
- if loop == 1000 then
- loop = 0
- sleep(.1)
- else
- loop = loop + 1
- end
- end
- console("Loaded "..i.." out of "..#file_info..": "..math.floor((i/#file_info)*100).."%")
- end
- --error(#byte_file_info[1]) -- should return # of lines of this program
- console(#byte_file_info.." File(s) converted Successfully!", true)
- console("Attempting to decrypt "..#byte_file_info.." file(s)...")
- for i=1, #byte_file_info do -- repeats only twice
- local loop = 1
- local d_loop = 0
- for ii=1, #byte_file_info[i] do -- repeats 300+ times
- for iii=1, #byte_file_info[i][ii] do
- byte_file_info[i][ii][iii] = byte_file_info[i][ii][iii]-pass[loop]
- if byte_file_info[i][ii][iii] < 1 then
- byte_file_info[i][ii][iii] = byte_file_info[i][ii][iii]+255
- end
- loop = loop + 1
- if loop > #pass then
- loop = 1
- end
- end
- if d_loop == 1000 then
- d_loop = 0
- console(fs.getName(full_list[i])..": "..ii.."/"..#byte_file_info[i].." "..math.floor((ii/#byte_file_info[i])*10).."%")
- else
- d_loop = d_loop + 1
- end
- --console("Debug: "..i.."/"..ii)
- end
- console("Decrypted "..i.." out of "..#byte_file_info.." : "..math.floor((i/#byte_file_info)*100).."%") sleep(.1)
- end
- console("Decryption Done!",true)
- console("Saving file(s)...",true)
- --error(#byte_file_info[1])
- for i=1, #byte_file_info do
- local file = fs.open(string.gsub(location,"_encry","").."_decry/"..string.gsub(full_list[i],location,""), "w")
- if notnil(file) then
- for ii=1, #byte_file_info[i] do
- for iii=1, #byte_file_info[i][ii] do
- file.write(string.char(byte_file_info[i][ii][iii]))
- end
- file.writeLine("")
- end
- file.close()
- console("Saving: "..i.."/"..#byte_file_info.." "..math.floor((i/#byte_file_info)*100).."%")
- else
- console("Error saving to file, this can happen for many reasons.",false)
- end
- end
- console("Save Finished! Done.",true)
- console("Thank you. Made by Just Does Games!",true) sleep(1)
- return true
- end
- -- main functions --
- -- Separate functions from Encryption --
- local function engine()
- cp(1,1) setText("white") setBack("black") clr()
- --encrypt("WHOLE_COMPUTER_COPY","Password")
- --decrypt("startup_encry.lua","Password")
- console("Welcome! type 'help' to display commands.")
- local commands = {
- help = function()
- console("List of commands")
- console(" - 'encrypt' -> encrypt a file")
- console(" - 'decrypt' -> decrypt a file")
- console(" - 'exit' -> exit the program")
- end,
- encrypt = function()
- console("Encryption",true)
- console("Enter directory or file name...")
- file = read()
- if fs.exists(file) then
- if fs.isDir(file) then
- console("Directory found!",true)
- else
- console("File found!",true)
- end
- console("Enter encryption password...",true)
- pass = read()
- if string.len(pass) < 1 then
- console("Encryption password has to be something!",false)
- else
- console("Confirm password: "..pass)
- console("Type 'yes' to confirm...",true)
- conf = read()
- if conf == "yes" then
- console("Encryption has started!") sleep(1)
- encrypt(file, pass)
- else
- console("Failed to confirm. Exiting...",false)
- end
- end
- else
- console("File or directory does not exists",false)
- end
- end,
- decrypt = function()
- console("Decryption",true)
- console("Enter directory or file name...")
- file = read()
- if fs.exists(file) then
- if fs.isDir(file) then
- console("Directory found!",true)
- else
- console("File found!",true)
- end
- console("Enter decryption password...",true)
- pass = read()
- if string.len(pass) < 1 then
- console("Decryption password has to be something!",false)
- else
- console("Confirm password: "..pass)
- console("Type 'yes' to confirm...",true)
- conf = read()
- if conf == "yes" then
- console("Decryption has started!") sleep(1)
- decrypt(file, pass)
- else
- console("Failed to confirm. Exiting...",false)
- end
- end
- else
- console("File or directory does not exists",false)
- end
- end,
- exit = function()
- console("Exiting...") running = false
- end
- }
- while running do
- local res = string.lower(read())
- if notnil(commands[res]) then
- commands[res]()
- else
- console("Unknown command? do 'help' for help.")
- end
- end
- end
- engine()
- print("")
- -- Separate functions from Encryption --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement