Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Migrate Encryption
- -- Decrypt Autorun
- local pass
- -- Turns off debug so people can't steel mi password
- _G.debug = nil
- -- Encryption API
- -- Nathan's Basic Encryption Library
- -- Encryption API
- -- Nathan's Basic Encryption Library
- local function encrypt(str, password, iter)
- iter = iter or 0
- -- Make Seed
- local seed = 0
- local seedtable = {string.byte(password, 1, -1)}
- math.randomseed(string.byte(password, -1) * string.byte(password, 1))
- for k,v in pairs(seedtable) do
- math.random() math.random()
- local operation = math.random(4)
- if operation == 1 then
- seed = seed + v
- elseif operation == 2 then
- seed = seed - v
- elseif operation == 3 then
- seed = seed * v
- elseif operation == 4 then
- seed = seed / v
- end
- seed = math.ceil(seed)
- end
- -- Start Encryption Process
- math.randomseed(seed)
- for i=1,iter do
- math.random()
- end
- local cipher = ""
- for i=1,#str do
- if string.byte(str, i) == 10 then
- cipher = cipher..str:sub(i,i)
- else
- local randseed = seedtable[math.random(#seedtable)]
- while string.byte(str, i)+randseed == 10 or string.byte(str, i)-randseed == 10 do
- randseed = seedtable[math.random(#seedtable)]
- end
- if string.byte(str, i)+randseed > 255 then
- randseed = -randseed
- end
- cipher = cipher..string.char(string.byte(str, i)+randseed)
- end
- end
- return cipher
- end
- local function decrypt(cipher, password, iter)
- iter = iter or 0
- -- Check for args
- if cipher == nil then
- return nil
- end
- -- Make Seed
- local seed = 0
- local seedtable = {string.byte(password, 1, -1)}
- math.randomseed(string.byte(password, -1) * string.byte(password, 1))
- for k,v in pairs(seedtable) do
- math.random() math.random()
- local operation = math.random(4)
- if operation == 1 then
- seed = seed + v
- elseif operation == 2 then
- seed = seed - v
- elseif operation == 3 then
- seed = seed * v
- elseif operation == 4 then
- seed = seed / v
- end
- seed = math.ceil(seed)
- end
- -- Start Encryption Process
- math.randomseed(seed)
- for i=1,iter do
- math.random()
- end
- local str = ""
- for i=1,#cipher do
- if string.byte(cipher, i) == 10 then
- str = str..cipher:sub(i,i)
- else
- local randseed = seedtable[math.random(#seedtable)]
- while string.byte(cipher, i)+randseed == 10 or string.byte(cipher, i)-randseed == 10 do
- randseed = seedtable[math.random(#seedtable)]
- end
- if string.byte(cipher, i)-randseed < 0 then
- randseed = -randseed
- end
- str = str..string.char(string.byte(cipher, i)-randseed)
- end
- end
- return str
- end
- print("Testing Encryption System")
- local success, returned = pcall(function() return decrypt(encrypt("hellowurld",string.char(128)..string.char(0)), string.char(128)..string.char(0)) end)
- if not success or returned ~= "hellowurld" then error("Test Failed: "..returned) else print("Success!") end
- print("Enter key: ")
- pass = read("*")
- print("Rewriting fs API...")
- -- Set up encryption
- local oldfsopen = fs.open
- local thisname = shell.getRunningProgram()
- _G.fs.open = function(dir, mode)
- if dir and (dir:sub(1,5) == "/rom/" or dir:sub(1,4) == "rom/" or dir:sub(1,4) == "disk" or dir:sub(1,5) == "/disk" or thisname == dir) then
- return oldfsopen(dir, mode)
- end
- local fopen = oldfsopen(dir, mode)
- if not fopen then return nil end
- local charIter = 0
- local returntable = {}
- returntable["readLine"] = function()
- local results = fopen.readLine()
- local dresult = decrypt(results, pass, charIter)
- if dresult then
- charIter = charIter+#dresult+1
- end
- return dresult
- end
- returntable.readAll = function()
- local results
- local dresult = ""
- repeat
- results = fopen.readLine()
- local rawresult = decrypt(results, pass, charIter)
- if rawresult then
- charIter = charIter+#rawresult+1
- dresult = dresult..rawresult.."\n"
- end
- until not results
- return dresult
- end
- returntable["write"] = function(data)
- -- Detect bunary mode
- if type(data) == "number" then
- data = string.char(data)
- end
- local dresult = fopen.write(encrypt(data, pass, charIter))
- if data then
- charIter = charIter+#data
- end
- return dresult
- end
- returntable["writeLine"] = function(data)
- local dresult = fopen.writeLine(encrypt(data, pass, charIter))
- if data then
- charIter = charIter+#data+1
- end
- return dresult
- end
- returntable["flush"] = fopen.flush
- returntable["read"] = function()
- local dresult = string.byte(decrypt(string.char(fopen.read()), pass, charIter))
- charIter = charIter+1
- return dresult
- end
- -- Essential Functions
- returntable["close"] = fopen.close
- return returntable
- end
- print("Done!")
- print("Migrating files in root...")
- function scanAllFiles(dir, r)
- local files = {}
- for _,v in pairs(fs.list(dir)) do
- if fs.isDir(v) then
- if v:sub(1,3) ~= "rom" and v:sub(1,7) ~= "startup" and r then
- local subfiles = scanAllFiles(v,r)
- for _,v1 in pairs(subfiles) do
- table.insert(files,v.."/"..v1)
- end
- end
- else
- table.insert(files, v)
- end
- end
- return files
- end
- local files = scanAllFiles("", true)
- for _,v in pairs(files) do
- local f = oldfsopen(v, "r")
- local migrate = encrypt(f.readAll(), pass)
- f.close()
- local f1 = oldfsopen(v, "w")
- f1.write(migrate)
- f1.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement