Advertisement
Tatantyler

XOR Decryptor

Nov 25th, 2012
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. local args = {...}
  2.  
  3. if #args < 2 then
  4.     print("USAGE: decryptor [key] [side]")
  5. end
  6.  
  7. local key = tonumber(args[1])
  8. math.randomseed(os.time())
  9.  
  10. local chars = {
  11.     "a",
  12.     "b",
  13.     "c",
  14.     "d",
  15.     "e",
  16.     "f",
  17.     "g",
  18.     "h",
  19.     "i",
  20.     "j",
  21.     "k",
  22.     "l",
  23.     "m",
  24.     "n",
  25.     "o",
  26.     "p",
  27.     "q",
  28.     "r",
  29.     "s",
  30.     "t",
  31.     "u",
  32.     "v",
  33.     "w",
  34.     "x",
  35.     "y",
  36.     "z",
  37.     " ",
  38.     "_",
  39.     "#",
  40.     "@",
  41.     "!",
  42.     "*",
  43.     "^",
  44.     "1",
  45.     "2",
  46.     "3",
  47.     "4",
  48.     "5",
  49.     "6",
  50.     "7",
  51.     "8",
  52.     "9",
  53.     "0",
  54.     "+",
  55.     "-",
  56.     "~",
  57.     "`",
  58.     "%",
  59.     "$",
  60.     "{",
  61.     "}",
  62.     "\\",
  63.     "/",
  64.     ">",
  65.     "<",
  66.     ";",
  67.     ":",
  68. }
  69. local function generateRandomChar(includeUpper)
  70.     local char = chars[math.random(1,#chars)]
  71.     if includeUpper then
  72.         local doUpper = math.random(1,2)
  73.         if doUpper == 2 then
  74.             char = string.upper(char)
  75.         end
  76.     end
  77.     return char
  78. end
  79.  
  80. local function doDecrypt(side)
  81.     local lines = {}
  82.     local currentLine = ""
  83.     local path = fs.combine(disk.getMountPath(side), "data")
  84.     local handle = fs.open(path, "rb")
  85.     while true do
  86.         local byte = handle.read()
  87.         if byte then
  88.             byte = bit.bxor(byte, key)
  89.             currentLine = currentLine..string.char(byte)
  90.             if string.char(byte) == "\n" then
  91.                 table.insert(lines, currentLine)
  92.                 currentLine = ""
  93.             end
  94.         else
  95.             break
  96.         end
  97.     end
  98.     handle.close()
  99.     return lines
  100. end
  101.  
  102. local function lookCool(lines)
  103.     for i,v in ipairs(lines) do
  104.         local coolStr = ""
  105.         for progress=1, 20 do
  106.             for i=1, #v do
  107.                 coolStr = coolStr..generateRandomChar(true)
  108.             end
  109.             term.clear()
  110.             term.setCursorPos(1,1)
  111.             print("Currently decrypting line "..i.."...")
  112.             print("Line Progress: "..math.floor((progress/20)*100).."%")
  113.             print("Total Progress: "..math.floor((i/#lines)*100).."%")
  114.             print("Current Attempt:")
  115.             print(coolStr)
  116.             coolStr = ""
  117.             os.sleep(0.5)
  118.         end
  119.         local handle = fs.open("decrypted.data", "a")
  120.         handle.write(v)
  121.         handle.close()
  122.     end
  123.     term.clear()
  124.     term.setCursorPos(1,1)
  125.     print("Done!")
  126.     print("Data written to \"decrypted.data\".")
  127. end
  128.  
  129. lookCool(doDecrypt(args[2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement