Advertisement
Chickenbreadlp

Syscrypt_decrypt

May 16th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.98 KB | None | 0 0
  1. --[[
  2.     MIT License
  3.  
  4.     Copyright © 2016 Chickenbreadlp
  5.  
  6.     Permission is hereby granted, free of charge, to any person obtaining a copy
  7.     of this software and associated documentation files (the "Software"), to deal
  8.     in the Software without restriction, including without limitation the rights
  9.     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.     copies of the Software, and to permit persons to whom the Software is
  11.     furnished to do so, subject to the following conditions:
  12.  
  13.     The above copyright notice and this permission notice shall be included in all
  14.     copies or substantial portions of the Software.
  15.  
  16.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.     SOFTWARE.
  23. ]]
  24.  
  25. local function unfoldkey(keyinput)
  26.  math.randomseed(tonumber(keyinput, 36))
  27.  y = {}
  28.  z = {}
  29.  for i=1, 16 do
  30.   y[i] = math.random(0, 0xFF)
  31.   z[i] = math.random(0, 0xFF)
  32.  end
  33.  math.randomseed(math.random())
  34.  return y, z
  35. end
  36.  
  37. local function encrypt(dir)
  38.  if dir == nil then dir = "" end
  39.  local ListFiles = fs.list(dir)
  40.  for _, file in ipairs(ListFiles) do
  41.   if fs.isDir(dir..file) then
  42.    if file ~= "rom" and file ~= ".syscrypt" and file ~= ".SyscryptShut" then
  43.     encrypt(dir.."/"..file.."/")
  44.    end
  45.   else
  46.    if file == "startup" then
  47.    else
  48.     local prog = fs.open(dir.."/"..file, "rb")
  49.     local progData = {}
  50.     local progbyte = prog.read()
  51.     repeat
  52.      table.insert(progData, progbyte)
  53.      progbyte = prog.read()
  54.     until progbyte == nil
  55.     prog.close()
  56.     progData = ccaes.encrypt_bytestream(progData, y, z)
  57.     local prog = fs.open(dir.."/"..file, "wb")
  58.     for i=1, #progData do
  59.      prog.write(progData[i])
  60.     end
  61.     prog.close()
  62.     sleep(0.01)
  63.    end
  64.   end
  65.  end
  66. end
  67.  
  68. local y = {}
  69. local z = {}
  70.  
  71. if fs.exists("/User/.SyscryptSetup") then
  72.  fs.delete("/User/.SyscryptSetup")
  73. end
  74.  
  75. if fs.exists("/User/.SyscryptShut") then
  76.  fs.delete("/User/.SyscryptShut")
  77. end
  78.  
  79. if syscrypt_alredydecrypt == true then
  80.  shell.run("/.syscrypt/boot")
  81. elseif fs.exists("/.syscrypt/.reboot") then
  82.  
  83.  local file = fs.open("/.syscrypt/.reboot", "r")
  84.  syscrypt_keyhash = file.readLine()
  85.  file.close()
  86.  
  87.  os.loadAPI("/.syscrypt/hash")
  88.  os.loadAPI("/.syscrypt/ccaes")
  89.  
  90.  local oshut = os.shutdown
  91.  os.shutdown = function()
  92.   fs.delete("/.syscrypt/.reboot")
  93.   if fs.exists("/ReboOSt") and login == true then
  94.    if fs.exists("/User/.SyscryptShut/..meta") then
  95.     fs.delete("/User/.SyscryptShut/..meta")
  96.    end
  97.    fs.makeDir("/User/.SyscryptShut/")
  98.    local file = fs.open("/User/.SyscryptShut/..meta", "w")
  99.    if admin then
  100.     file.writeLine(hash.sha256(UserPass.."admin"))
  101.    else
  102.     file.writeLine(hash.sha256(UserPass.."stand"))
  103.    end
  104.    file.close()
  105.    UserName = ".SyscryptShut"
  106.   end
  107.   y, z = unfoldkey(syscrypt_keyhash)
  108.   encrypt()
  109.   oshut()
  110.  end
  111.  syscrypt_alredydecrypt = true
  112.  term.clear()
  113.  term.setCursorPos(1,1)
  114.  if fs.exists("/.syscrypt/boot") then
  115.   shell.run("/.syscrypt/boot")
  116.  else
  117.   shell.run("shell")
  118.  end
  119. else
  120.  
  121. os.loadAPI("/.syscrypt/hash")
  122. os.loadAPI("/.syscrypt/ccaes")
  123. term.setBackgroundColor(colors.black)
  124. term.setTextColor(colors.white)
  125. term.clear()
  126. local textXI = (52 - string.len("This Computer has been protected with Syscrypt")) / 2
  127. local textXV = (52 - string.len("To decrypt, enter in your password below")) / 2
  128. term.setCursorPos(textXI, 3)
  129. print("This Computer has been protected with Syscrypt")
  130. term.setCursorPos(textXV, 4)
  131. print("To decrypt, enter in your password below")
  132. while true do
  133.  term.setCursorPos(1,7)
  134.  term.clearLine()
  135.  term.setCursorPos(1,8)
  136.  term.clearLine()
  137.  term.setCursorPos(1,7)
  138.  write("Password: ")
  139.  local oldpe = os.pullEvent()
  140.  os.pullEvent = os.pullEventRaw
  141.  syscrypt_keyhash = hash.sha256(read("*"))
  142.  shell.run("/.syscrypt/reference_key")
  143.  if hash.sha256(syscrypt_keyhash) == syscrypt_key then
  144.   y, z = unfoldkey(syscrypt_keyhash)
  145.  
  146.   local function decrypt(dir)
  147.    if dir == nil then dir = "" end
  148.    local ListFiles = fs.list(dir)
  149.    for _, file in ipairs(ListFiles) do
  150.     if fs.isDir(dir..file) then
  151.      if file ~= "rom" and file ~= ".syscrypt" then
  152.       term.setTextColor(colors.lime)
  153.       decrypt(dir.."/"..file.."/")
  154.      end
  155.     else
  156.      if file == "startup" then
  157.      else
  158.       local prog = fs.open(dir.."/"..file, "rb")
  159.       local progData = {}
  160.       local progbyte = prog.read()
  161.       repeat
  162.       table.insert(progData, progbyte)
  163.       progbyte = prog.read()
  164.       until progbyte == nil
  165.       prog.close()
  166.       progData = ccaes.decrypt_bytestream(progData, y, z)
  167.       local prog = fs.open(dir.."/"..file, "wb")
  168.       for i=1, #progData do
  169.        prog.write(progData[i])
  170.       end
  171.       prog.close()
  172.       sleep(0.01)
  173.      end
  174.     end
  175.    end
  176.   end
  177.  
  178.   decrypt()
  179.  
  180.   local file = fs.open("/.syscrypt/.reboot", "w")
  181.   file.writeLine(syscrypt_keyhash)
  182.   file.close()
  183.  
  184.   local oshut = os.shutdown
  185.   os.shutdown = function()
  186.    fs.delete("/.syscrypt/.reboot")
  187.    if fs.exists("/ReboOSt") and login == true then
  188.     if fs.exists("/User/.SyscryptShut/..meta") then
  189.      fs.delete("/User/.SyscryptShut/..meta")
  190.     end
  191.     fs.makeDir("/User/.SyscryptShut/")
  192.     local file = fs.open("/User/.SyscryptShut/..meta", "w")
  193.     if admin then
  194.      file.writeLine(hash.sha256(UserPass.."admin"))
  195.     else
  196.      file.writeLine(hash.sha256(UserPass.."stand"))
  197.     end
  198.     file.close()
  199.     UserName = ".SyscryptShut"
  200.    end
  201.    y, z = unfoldkey(syscrypt_keyhash)
  202.    encrypt()
  203.    oshut()
  204.   end
  205.  
  206.   syscrypt_alredydecrypt = true
  207.   term.clear()
  208.   term.setCursorPos(1,1)
  209.   if fs.exists("/.syscrypt/boot") then
  210.    shell.run("/.syscrypt/boot")
  211.   else
  212.    shell.run("shell")
  213.   end
  214.   break
  215.  else
  216.   printError("Wrong Password!")
  217.   sleep(2)
  218.  end
  219. end
  220. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement