Guest User

crypt

a guest
Feb 20th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. function Crypt(path,pass)
  2.     if fs.exists(path) and not fs.isDir(path) and path ~= "/startup" and path ~= "/crypt" then
  3.         write("[FILE]: "..path.."... ")
  4.         local Tab={}
  5.         local F = fs.open(path,"rb")
  6.         while true do
  7.             local N = F.read()
  8.             if N == nil then break end
  9.             table.insert(Tab,N)
  10.         end
  11.         F.close()
  12.         F = fs.open(path,"wb")
  13.         for k, v in pairs(Tab) do
  14.             F.write(bit.bxor(v,string.byte(pass,k%string.len(pass)+1)))
  15.         end
  16.         F.close()
  17.        
  18.         print("[DONE]")
  19.     end
  20. end
  21.  
  22. function CryptIn(path,pass)
  23.     if fs.exists(path) and fs.isDir(path) and path ~= "/rom" and path ~= "/disk" then
  24.         for k, v in pairs(fs.list(path)) do
  25.             if fs.isDir(path.."/"..v) then
  26.                 CryptIn(path.."/"..v,pass)
  27.             else
  28.                 Crypt(path.."/"..v,pass)
  29.             end
  30.         end
  31.     end
  32. end
  33.  
  34. local msg
  35. local pass
  36.  
  37. if not fs.exists("_TMSG") then
  38.     print("[Encoding]")
  39.     write("Enter Password: ")
  40.     pass = read("*")
  41.     write("Enter Test Message: ")
  42.     msg = read()
  43.     local F = fs.open("_TMSG","w")
  44.         F.write(msg)
  45.     F.close()
  46. else
  47.     print("[Decoding]")
  48.     write("Enter Password: ")
  49.     pass = read("*")
  50.     Crypt("_TMSG",pass)
  51.     write("Test Message: ")
  52.     local F = fs.open("_TMSG","r")
  53.         print(F.readAll())
  54.     F.close()
  55.     write("Continue?[Y/N]: ")
  56.     while true do
  57.         local YN = read()
  58.         if YN == "Y" then
  59.             fs.delete("_TMSG")
  60.             break
  61.         elseif YN == "N" then
  62.             Crypt("_TMSG",pass)
  63.             return
  64.         end
  65.     end
  66. end
  67.  
  68. CryptIn("",pass)
Advertisement
Add Comment
Please, Sign In to add comment