Advertisement
Guest User

package

a guest
Jul 16th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 51.66 KB | None | 0 0
  1. local c="{\
  2.  upgrader = \"function getPrints(coord1, coord2)\\\
  3. \\\
  4.  smallCoord = {0,0,0}\\\
  5.  bigCoord = {0,0,0}\\\
  6. \\\
  7.  buildingMaterials = {\\\
  8.    \\\"minecraft:stone\\\",\\\
  9.    \\\"minecraft:stonebrick\\\",\\\
  10.    \\\"minecraft:torch\\\",\\\
  11.    \\\"minecraft:glass\\\"\\\
  12.  }\\\
  13. \\\
  14.  bluePrints = {}\\\
  15. \\\
  16.  for i = 1, 3 do\\\
  17.    if coord1[i] < coord2[i] then\\\
  18.      smallCoord[i] = coord1[i]\\\
  19.      bigCoord[i] = coord2[i]\\\
  20.    else\\\
  21.      smallCoord[i] = coord2[i]\\\
  22.      bigCoord[i] = coord1[i]\\\
  23.    end\\\
  24.  end\\\
  25. \\\
  26.  for x = smallCoord[1], bigCoord[1] do\\\
  27.    table.insert(bluePrints, {})\\\
  28.    for y = smallCoord[2], bigCoord[2] do\\\
  29.      table.insert(bluePrints[x-smallCoord[1]+1],{})\\\
  30.      for z = smallCoord[3], bigCoord[3] do\\\
  31.        isBlock = false\\\
  32.        for i,v in ipairs(buildingMaterials) do\\\
  33.          if commands.exec(\\\"testforblock \\\"..x..\\\" \\\"..y..\\\" \\\"..z..\\\" \\\"..v) then\\\
  34.            table.insert(bluePrints[x-smallCoord[1]+1][y-smallCoord[2]+1],v)\\\
  35.            isBlock = true\\\
  36.          end\\\
  37.        end\\\
  38.      \\\
  39.        if not isBlock then\\\
  40.          table.insert(bluePrints[x-smallCoord[1]+1][y-smallCoord[2]+1],\\\"minecraft:air\\\")\\\
  41.        end\\\
  42.      end\\\
  43.    end\\\
  44.  end\\\
  45.  \\\
  46.  return {coord1,coord2,bluePrints,false}\\\
  47. end\\\
  48. \\\
  49. function writePrints(pack,name)\\\
  50.  file = fs.open(\\\"upgrades/\\\"..name,\\\"w\\\")\\\
  51.  file.write(textutils.serialise(pack))\\\
  52.  file.close()\\\
  53. end\\\
  54. \\\
  55. function reset(name)\\\
  56.  if not fs.exists(\\\"upgrades/\\\"..name) then\\\
  57.    return\\\
  58.  end\\\
  59.  \\\
  60.  file = fs.open(\\\"upgrades/\\\"..name,\\\"r\\\")\\\
  61.  data = file.readAll()\\\
  62.  file.close()\\\
  63.  t = textutils.unserialise(data)\\\
  64.  \\\
  65.  t[4] = false\\\
  66. \\\
  67. if not fs.exists(\\\"upgrades/\\\"..name) then\\\
  68.    return\\\
  69.  else\\\
  70.    file = fs.open(\\\"upgrades/\\\"..name, \\\"r\\\")\\\
  71.    data = file.readAll()\\\
  72.    file.close()\\\
  73.    pack = textutils.unserialise(data)\\\
  74.  end\\\
  75.  \\\
  76.  prints = pack[3]\\\
  77.  coord1 = pack[1]\\\
  78.  coord2 = pack[2]\\\
  79. \\\
  80.  smallCoord = {0,0,0}\\\
  81.  bigCoord = {0,0,0}\\\
  82. \\\
  83.  for i=1,3 do\\\
  84.    if coord1[i] < coord2[i] then\\\
  85.      smallCoord[i] = coord1[i]\\\
  86.      bigCoord[i] = coord2[i]\\\
  87.    else\\\
  88.      smallCoord[i] = coord2[i]\\\
  89.      bigCoord[i] = coord1[i]\\\
  90.    end\\\
  91.  end\\\
  92.  \\\
  93.  for x=smallCoord[1], bigCoord[1] do\\\
  94.    for y=smallCoord[2], bigCoord[2] do\\\
  95.      for z=smallCoord[3], bigCoord[3] do\\\
  96.        material = prints[x-smallCoord[1]+1][y-smallCoord[2]+1][z-smallCoord[3]+1]\\\
  97.        if not (material == \\\"minecraft:air\\\") then\\\
  98.          commands.exec(\\\"setblock \\\"..x..\\\" \\\"..y..\\\" \\\"..z..\\\" minecraft:air\\\")\\\
  99.        end\\\
  100.      end\\\
  101.    end\\\
  102.  end\\\
  103.  \\\
  104.  writePrints(t,name)\\\
  105. end\\\
  106.  \\\
  107. function getBoughten(name)\\\
  108.  if not fs.exists(\\\"upgrades/\\\"..name) then\\\
  109.    return false\\\
  110.  end\\\
  111.  \\\
  112.  file = fs.open(\\\"upgrades/\\\"..name,\\\"r\\\")\\\
  113.  data = file.readAll()\\\
  114.  file.close()\\\
  115.  t = textutils.unserialise(data)\\\
  116.  \\\
  117.  return t[4]\\\
  118. end\\\
  119. \\\
  120. function build(name)\\\
  121.  \\\
  122.  if not fs.exists(\\\"upgrades/\\\"..name) then\\\
  123.    return\\\
  124.  else\\\
  125.    file = fs.open(\\\"upgrades/\\\"..name, \\\"r\\\")\\\
  126.    data = file.readAll()\\\
  127.    file.close()\\\
  128.    pack = textutils.unserialise(data)\\\
  129.  end\\\
  130.  \\\
  131.  prints = pack[3]\\\
  132.  coord1 = pack[1]\\\
  133.  coord2 = pack[2]\\\
  134. \\\
  135.  smallCoord = {0,0,0}\\\
  136.  bigCoord = {0,0,0}\\\
  137. \\\
  138.  for i=1,3 do\\\
  139.    if coord1[i] < coord2[i] then\\\
  140.      smallCoord[i] = coord1[i]\\\
  141.      bigCoord[i] = coord2[i]\\\
  142.    else\\\
  143.      smallCoord[i] = coord2[i]\\\
  144.      bigCoord[i] = coord1[i]\\\
  145.    end\\\
  146.  end\\\
  147.  \\\
  148.  for x=smallCoord[1], bigCoord[1] do\\\
  149.    for y=smallCoord[2], bigCoord[2] do\\\
  150.      for z=smallCoord[3], bigCoord[3] do\\\
  151.        material = prints[x-smallCoord[1]+1][y-smallCoord[2]+1][z-smallCoord[3]+1]\\\
  152.        if not (material == \\\"minecraft:air\\\") then\\\
  153.          commands.exec(\\\"setblock \\\"..x..\\\" \\\"..y..\\\" \\\"..z..\\\" \\\"..material)\\\
  154.        end\\\
  155.      end\\\
  156.    end\\\
  157.  end\\\
  158. \\\
  159.  pack[4] = true\\\
  160.  \\\
  161.  writePrints(pack,name)\\\
  162. end\",\
  163.  startup = \"key = \\\"your my favorite deputy\\\"\\\
  164. \\\
  165. os.loadAPI(\\\"upgrader\\\")\\\
  166. os.loadAPI(\\\"sUtils\\\")\\\
  167. \\\
  168. MBC = 8\\\
  169. mainServer = 0\\\
  170. defenseComputer = 10\\\
  171. modemSide = \\\"top\\\"\\\
  172. \\\
  173. infiltrationTime = 5\\\
  174. attacker = -1\\\
  175. attackID = \\\"\\\"\\\
  176. infiltrateTimer = -2\\\
  177. rebootTimer = -2\\\
  178. \\\
  179. rednet.open(modemSide)\\\
  180. \\\
  181. beds = {\\\
  182.  --Coords of non pillow part of bed, name\\\
  183.  {146, 8, -245,\\\"MainBed\\\"},\\\
  184.  {145, 4, -245,\\\"Bed1\\\"},\\\
  185.  {147, 4, -245,\\\"Bed2\\\"}\\\
  186. }\\\
  187. \\\
  188. doors = {\\\
  189.  -- {ID, \\\"OFFLINE\\\", name}\\\
  190.  {11,\\\"OFFLINE\\\",\\\"MainGate\\\"}\\\
  191. }\\\
  192. \\\
  193. upgrades = {\\\
  194.  --name, cost\\\
  195. }\\\
  196. \\\
  197. monitors = {\\\
  198.  --ID\\\
  199.  12,14,16\\\
  200. }\\\
  201. \\\
  202. \\\
  203. if not fs.exists(\\\"/serverDat\\\") then\\\
  204.  rednet.send(mainServer,{\\\"get_controller\\\"})\\\
  205.  id,msg,d = rednet.receive(.3)\\\
  206.  if msg == nil or id ~= mainServer then\\\
  207.    print(\\\"SERVER ERROR\\\")\\\
  208.    return\\\
  209.  end\\\
  210.  controller = msg\\\
  211.  \\\
  212.  file = fs.open(\\\"/serverDat/controller\\\",\\\"w\\\")\\\
  213.  file.write(textutils.serialise(controller))\\\
  214.  file.close()\\\
  215. else\\\
  216.  file = fs.open(\\\"/serverDat/controller\\\",\\\"r\\\")\\\
  217.  data = file.readAll()\\\
  218.  file.close()\\\
  219.  controller = textutils.unserialise(data)\\\
  220. end\\\
  221. \\\
  222. function update()\\\
  223.  file = fs.open(\\\"/serverDat/controller\\\",\\\"w\\\")\\\
  224.  file.write(textutils.serialise(controller))\\\
  225.  file.close()\\\
  226. end\\\
  227. \\\
  228. underAttack = false\\\
  229. infiltrated = false\\\
  230. \\\
  231. while true do\\\
  232.  e,p1,p2,p3,p4 = os.pullEvent()\\\
  233.  \\\
  234.  if e == \\\"modem_message\\\" then\\\
  235.    id = p3\\\
  236.    message = p4[\\\"message\\\"]\\\
  237.    \\\
  238.    print(textutils.serialise(message))\\\
  239.    print(id)\\\
  240.    \\\
  241.    if id == MBC and type(message[1]) == \\\"string\\\" and not infiltrated then\\\
  242.      print(\\\"LOGGING IN\\\")\\\
  243.      username = message[2]\\\
  244.      password = message[3]\\\
  245.      \\\
  246.      print(sUtils.decrypt(password,key))\\\
  247.      print(controller[3])\\\
  248.        \\\
  249.      if username == controller[1] and sUtils.decrypt(password,key) == controller[3] then\\\
  250.        sleep(.2)\\\
  251.        rednet.send(mainServer,{\\\"log_in\\\",username,password})\\\
  252.        id2,msg2,d2 = rednet.receive(.3)\\\
  253.        print(\\\"MESSAGE AFTER LOG IN\\\")\\\
  254.        print(textutils.serialise(msg2))\\\
  255.        print(id2)\\\
  256.        if id2 == mainServer then\\\
  257.          print(\\\"Yay!\\\")\\\
  258.          rednet.send(id,msg2)\\\
  259.        end\\\
  260.      end\\\
  261.    elseif id == MBC and type(message[1]) == \\\"string\\\" and infiltrated then\\\
  262.      \\\
  263.      rednet.send(id,{\\\"HACKER\\\",0,\\\"HACKER\\\"})\\\
  264.      \\\
  265.    elseif type(message) == \\\"table\\\" and (id == MBC and infiltrated) then\\\
  266.      sleep(.2)\\\
  267.      msg = message[2]\\\
  268.      \\\
  269.      if type(msg) == \\\"table\\\" then\\\
  270.        \\\
  271.        cmd = msg[1]\\\
  272.        \\\
  273.        if cmd == \\\"infiltrate\\\" then\\\
  274.          username = msg[2]\\\
  275.          password = msg[3]\\\
  276.          keyID = msg[4]\\\
  277.          \\\
  278.          print(\\\"KEY ID: \\\"..keyID)\\\
  279.          print(\\\"Attack ID: \\\"..attackID)\\\
  280.          \\\
  281.          if keyID == attackID then\\\
  282.            print(\\\"Success\\\")\\\
  283.            rednet.send(mainServer,{\\\"log_in\\\",username,password})\\\
  284.            id2,msg2,d2 = rednet.receive(.2)\\\
  285.            print(textutils.serialise(msg2))\\\
  286.            if id2 == mainServer then\\\
  287.              print(\\\"Another one\\\")\\\
  288.              controller[3] = sUtils.decrypt(controller[3],key)\\\
  289.              controller = msg2\\\
  290.              update()\\\
  291.              rednet.send(mainServer,{\\\"change_controller\\\",controller[1]}) \\\
  292.              rednet.send(id,true)\\\
  293.              for i,v in ipairs(monitors) do\\\
  294.                rednet.send(v, {\\\"end_attack\\\"})\\\
  295.              end\\\
  296.              infiltrated = false\\\
  297.              os.cancelTimer(rebootTimer)\\\
  298.              infiltrateTimer = -2\\\
  299.              rebootTimer = -2\\\
  300.              attacker = -1\\\
  301.              attackID = \\\"\\\"\\\
  302.              underAttack = false\\\
  303.              \\\
  304.              for i,v in ipairs(upgrades) do\\\
  305.                upgrader.reset(v[1])\\\
  306.              end\\\
  307.              \\\
  308.              rednet.send(defenseComputer,\\\"attack_undone\\\")\\\
  309.            end\\\
  310.          end\\\
  311.        elseif cmd == \\\"infiltrate_request\\\" then\\\
  312.          rednet.send(id,true)\\\
  313.        end\\\
  314.      end\\\
  315.    elseif type(message) == \\\"table\\\" and ((id == MBC and not infiltrated) or (id == mainServer) or (infiltrated and id == attacker)) then\\\
  316.      \\\
  317.      print(\\\"IT'S GOIN TO THE RIGHT PLACE\\\")\\\
  318.      allowed = false\\\
  319.      if id == MBC and type(message[1]) == \\\"table\\\" then\\\
  320.        print(\\\"HERE I AM\\\")\\\
  321.        user = message[1]\\\
  322.        user[3] = sUtils.decrypt(user[3],key)\\\
  323.        print(\\\"User: \\\"..user[3])\\\
  324.        print(\\\"Controller: \\\"..controller[3])\\\
  325.        if user[1] == controller[1] and user[3] == controller[3] then\\\
  326.          msg = message[2]\\\
  327.          allowed = true\\\
  328.        end\\\
  329.      elseif id == attacker or id == mainServer then\\\
  330.        if type(message[2]) == \\\"table\\\" then\\\
  331.          print(\\\"GOING HERE FOR SOME REASON\\\")\\\
  332.          print(id)\\\
  333.          msg = message[2]\\\
  334.          allowed = true\\\
  335.        end\\\
  336.      end\\\
  337.      \\\
  338.      if allowed then\\\
  339.        cmd = msg[1]\\\
  340.        print(cmd)\\\
  341.        print(infiltrated)\\\
  342.      \\\
  343.        if cmd == \\\"get_beds\\\" then\\\
  344.          print(\\\"GETTIN SOME BEDS\\\")\\\
  345.          returnArray = {}\\\
  346.      \\\
  347.          for i,v in ipairs(beds) do\\\
  348.            if commands.exec(\\\"testforblock \\\"..v[1]..\\\" \\\"..v[2]..\\\" \\\"..v[3]..\\\" minecraft:bed\\\") then\\\
  349.              table.insert(returnArray,{v[4],true})\\\
  350.            else\\\
  351.              table.insert(returnArray,{v[4],false})\\\
  352.            end\\\
  353.          end\\\
  354.          \\\
  355.          print(textutils.serialize(returnArray))\\\
  356.          print(id)\\\
  357.      \\\
  358.          sent = rednet.send(id,returnArray)\\\
  359.          print(sent)\\\
  360.        elseif cmd == \\\"change_bed\\\" then\\\
  361.          name = msg[2]\\\
  362.       \\\
  363.          for i,v in ipairs(beds) do\\\
  364.            if v[4] == name then\\\
  365.              if not commands.exec(\\\"testforblock \\\"..v[1]..\\\" \\\"..v[2]..\\\" \\\"..v[3]..\\\" minecraft:bed\\\") then\\\
  366.                commands.exec(\\\"setblock \\\"..v[1]..\\\" \\\"..v[2]..\\\" \\\"..(v[3]-1)..\\\" minecraft:bed 10\\\")\\\
  367.                commands.exec(\\\"setblock \\\"..v[1]..\\\" \\\"..v[2]..\\\" \\\"..v[3]..\\\" minecraft:bed 2\\\")\\\
  368.              else\\\
  369.                commands.exec(\\\"setblock \\\"..v[1]..\\\" \\\"..v[2]..\\\" \\\"..v[3]..\\\" minecraft:air\\\")\\\
  370.              end\\\
  371.            end\\\
  372.          end\\\
  373.        elseif cmd == \\\"get_doors\\\" then\\\
  374.          rednet.send(id, doors)\\\
  375.        elseif cmd == \\\"change_door\\\" then\\\
  376.          name = msg[2]\\\
  377.          \\\
  378.          for i,v in ipairs(doors) do\\\
  379.            if v[3] == name then\\\
  380.              rednet.send(v[1],\\\"change\\\")\\\
  381.              id3,msg3,d3 = rednet.receive(.3)\\\
  382.              print(textutils.serialise(msg3))\\\
  383.              print(id3)\\\
  384.              if id3 == v[1] then\\\
  385.                v[2] = msg3\\\
  386.              end\\\
  387.            end\\\
  388.          end\\\
  389.        elseif cmd == \\\"get_upgrades\\\" then\\\
  390.          returnArray = {}\\\
  391.          for i,v in ipairs(upgrades) do\\\
  392.            if not upgrader.getBoughten(v[1]) then\\\
  393.              table.insert(returnArray,v)\\\
  394.            end\\\
  395.          end\\\
  396.          \\\
  397.          rednet.send(id,returnArray)\\\
  398.        elseif cmd == \\\"buy_upgrade\\\" then\\\
  399.          name = msg[2]\\\
  400.      \\\
  401.          for i,v in ipairs(upgrades) do\\\
  402.            if v[1] == name then\\\
  403.              rednet.send(mainServer,{\\\"buy\\\",controller,v[2]})\\\
  404.              id2,msg,d = rednet.receive(.3)\\\
  405.              if id == mainServer and msg then\\\
  406.                controller[2] = controller[2] - v[2]\\\
  407.                upgrader.build(name)\\\
  408.                rednet.send(id,true)\\\
  409.              end\\\
  410.            end\\\
  411.          end\\\
  412.        elseif cmd == \\\"begin_attack\\\" and id == mainServer then\\\
  413.          underAttack = true\\\
  414.          defenseTime = msg[2]\\\
  415.          counter = msg[3]\\\
  416.          attacker = msg[4]\\\
  417.          attackID = msg[6]\\\
  418.          \\\
  419.          print(\\\"UNDER ATTACK\\\")\\\
  420.          \\\
  421.          for i,v in ipairs(monitors) do\\\
  422.            rednet.send(v,{\\\"start_attack\\\"})\\\
  423.          end\\\
  424.          rednet.send(defenseComputer,{\\\"under_attack\\\",msg[3],msg[2]})\\\
  425.          rednet.send(attacker,{\\\"attack_started\\\",defenseTime})\\\
  426.          print(defenseTime*60)\\\
  427.          infiltrateTimer = os.startTimer(defenseTime*60)\\\
  428.        end\\\
  429.      end\\\
  430.    elseif id == defenseComputer and underAttack and not infiltrated then\\\
  431.      cmd = message[1]\\\
  432.      \\\
  433.      if cmd == \\\"attack_undone\\\" then\\\
  434.      \\\
  435.        for i,v in ipairs(monitors) do\\\
  436.          rednet.send(v,{\\\"end_attack\\\"})\\\
  437.        end\\\
  438.        \\\
  439.        print(\\\"attack undone\\\")\\\
  440.        rednet.send(attacker,{\\\"attack_undone\\\"})\\\
  441.        rednet.send(defenseComputer,{\\\"attack_undone\\\"})\\\
  442.        underAttack = false\\\
  443.        os.cancelTimer(infiltrateTimer)\\\
  444.        infiltrateTimer = -2\\\
  445.        attacker = -1\\\
  446.        attackID = \\\"\\\"\\\
  447.      end\\\
  448.    end\\\
  449.  elseif e == \\\"timer\\\" then\\\
  450.    if p1 == infiltrateTimer then\\\
  451.      print(\\\"INFILTRATED\\\")\\\
  452.      infiltrated = true\\\
  453.      rednet.send(attacker,{\\\"infiltrated\\\",os.getComputerID()})\\\
  454.      rebootTimer = os.startTimer(infiltrationTime*60)\\\
  455.    elseif p1 == rebootTimer then\\\
  456.      print(\\\"SYSTEM REBOOTED\\\")\\\
  457.      infiltrated = false\\\
  458.      underAttack = false\\\
  459.      infiltrateTimer = -2\\\
  460.      rebootTimer = -2\\\
  461.      attacker = -1\\\
  462.      attackID = \\\"\\\"\\\
  463.    end\\\
  464.  end\\\
  465. end\\\
  466.    \",\
  467.  sUtils = \"--[[\\\
  468. Copyright (C) 2012 Thomas Farr a.k.a tomass1996 [farr.thomas@gmail.com]\\\
  469. \\\
  470. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and\\\
  471. associated documentation files (the \\\"Software\\\"), to deal in the Software without restriction,\\\
  472. including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,\\\
  473. copies of the Software, and to permit persons to whom the Software is furnished to do so,\\\
  474. subject to the following conditions:\\\
  475. \\\
  476. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\\\
  477. -Visible credit is given to the original author.\\\
  478. -The software is distributed in a non-profit way.\\\
  479. \\\
  480. THE SOFTWARE IS PROVIDED \\\"AS IS\\\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\\\
  481. WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\\\
  482. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\\\
  483. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\\\
  484. --]]\\\
  485. \\\
  486. local floor,modf, insert = math.floor,math.modf, table.insert\\\
  487. local char,format,rep = string.char,string.format,string.rep\\\
  488. \\\
  489. local function basen(n,b)\\\
  490.     if n < 0 then\\\
  491.         n = -n\\\
  492.     end\\\
  493.       local t = \\\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_abcdefghijklmnopqrstuvwxyz{|}~\\\"\\\
  494.   if n < b then\\\
  495.     local ret = \\\"\\\"\\\
  496.     ret = ret..string.sub(t, (n%b)+1,(n%b)+1)\\\
  497.     return ret\\\
  498.   else\\\
  499.     local tob = tostring(basen(math.floor(n/b), b))\\\
  500.     local ret = tob..t:sub((n%b)+1,(n%b)+1)\\\
  501.     return ret\\\
  502.   end\\\
  503. end\\\
  504. \\\
  505. local Base64 = {}\\\
  506. Base64[\\\"lsh\\\"] = function(value,shift)\\\
  507.    return (value*(2^shift)) % 256\\\
  508. end\\\
  509. Base64[\\\"rsh\\\"] = function(value,shift)\\\
  510.    return math.floor(value/2^shift) % 256\\\
  511. end\\\
  512. Base64[\\\"bit\\\"] = function(x,b)\\\
  513.    return (x % 2^b - x % 2^(b-1) > 0)\\\
  514. end\\\
  515. Base64[\\\"lor\\\"] = function(x,y)\\\
  516.    local result = 0\\\
  517.    for p=1,8 do result = result + (((Base64.bit(x,p) or Base64.bit(y,p)) == true) and 2^(p-1) or 0) end\\\
  518.    return result\\\
  519. end\\\
  520. Base64[\\\"base64chars\\\"] = {\\\
  521.    [0]='A',[1]='B',[2]='C',[3]='D',[4]='E',[5]='F',[6]='G',[7]='H',[8]='I',[9]='J',[10]='K',\\\
  522.    [11]='L',[12]='M',[13]='N',[14]='O',[15]='P',[16]='Q',[17]='R',[18]='S',[19]='T',[20]='U',\\\
  523.    [21]='V',[22]='W',[23]='X',[24]='Y',[25]='Z',[26]='a',[27]='b',[28]='c',[29]='d',[30]='e',\\\
  524.    [31]='f',[32]='g',[33]='h',[34]='i',[35]='j',[36]='k',[37]='l',[38]='m',[39]='n',[40]='o',\\\
  525.    [41]='p',[42]='q',[43]='r',[44]='s',[45]='t',[46]='u',[47]='v',[48]='w',[49]='x',[50]='y',\\\
  526.    [51]='z',[52]='0',[53]='1',[54]='2',[55]='3',[56]='4',[57]='5',[58]='6',[59]='7',[60]='8',\\\
  527.    [61]='9',[62]='-',[63]='_'}\\\
  528. Base64[\\\"base64bytes\\\"] = {\\\
  529.    ['A']=0,['B']=1,['C']=2,['D']=3,['E']=4,['F']=5,['G']=6,['H']=7,['I']=8,['J']=9,['K']=10,\\\
  530.    ['L']=11,['M']=12,['N']=13,['O']=14,['P']=15,['Q']=16,['R']=17,['S']=18,['T']=19,['U']=20,\\\
  531.    ['V']=21,['W']=22,['X']=23,['Y']=24,['Z']=25,['a']=26,['b']=27,['c']=28,['d']=29,['e']=30,\\\
  532.    ['f']=31,['g']=32,['h']=33,['i']=34,['j']=35,['k']=36,['l']=37,['m']=38,['n']=39,['o']=40,\\\
  533.    ['p']=41,['q']=42,['r']=43,['s']=44,['t']=45,['u']=46,['v']=47,['w']=48,['x']=49,['y']=50,\\\
  534.    ['z']=51,['0']=52,['1']=53,['2']=54,['3']=55,['4']=56,['5']=57,['6']=58,['7']=59,['8']=60,\\\
  535.    ['9']=61,['-']=62,['_']=63,['=']=nil}\\\
  536. \\\
  537. local base32 = \\\"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567\\\"\\\
  538. \\\
  539. local tSHA1 = {}\\\
  540. tSHA1[\\\"bytes_to_w32\\\"] = function(a,b,c,d) return a*0x1000000+b*0x10000+c*0x100+d end\\\
  541. tSHA1[\\\"w32_to_bytes\\\"] = function(i) return floor(i/0x1000000)%0x100,floor(i/0x10000)%0x100,floor(i/0x100)%0x100,i%0x100 end\\\
  542. tSHA1[\\\"w32_rot\\\"] = function(bits,a)\\\
  543.    local b2 = 2^(32-bits)\\\
  544.    local a,b = modf(a/b2)\\\
  545.    return a+b*b2*(2^(bits))\\\
  546. end\\\
  547. tSHA1[\\\"byte_to_bits\\\"] = function(b)\\\
  548.    local b = function (n)\\\
  549.        local b = floor(b/n)\\\
  550.        return b%2==1\\\
  551.    end\\\
  552.    return b(1),b(2),b(4),b(8),b(16),b(32),b(64),b(128)\\\
  553. end\\\
  554. tSHA1[\\\"bits_to_byte\\\"] = function(a,b,c,d,e,f,g,h)\\\
  555.    local function n(b,x) return b and x or 0 end\\\
  556.    return n(a,1)+n(b,2)+n(c,4)+n(d,8)+n(e,16)+n(f,32)+n(g,64)+n(h,128)\\\
  557. end\\\
  558. tSHA1[\\\"bits_to_string\\\"] = function(a,b,c,d,e,f,g,h)\\\
  559.    local function x(b) return b and \\\"1\\\" or \\\"0\\\" end\\\
  560.    return (\\\"%s%s%s%s %s%s%s%s\\\"):format(x(a),x(b),x(c),x(d),x(e),x(f),x(g),x(h))\\\
  561. end\\\
  562. tSHA1[\\\"byte_to_bit_string\\\"] = function(b) return tSHA1.bits_to_string(byte_to_bits(b)) end\\\
  563. tSHA1[\\\"w32_to_bit_string\\\"] = function(a)\\\
  564.    if type(a) == \\\"string\\\" then return a end\\\
  565.    local aa,ab,ac,ad = tSHA1.w32_to_bytes(a)\\\
  566.    local s = tSHA1.byte_to_bit_string\\\
  567.    return (\\\"%s %s %s %s\\\"):format(s(aa):reverse(),s(ab):reverse(),s(ac):reverse(),s(ad):reverse()):reverse()\\\
  568. end\\\
  569. tSHA1[\\\"band\\\"] = function(a,b)\\\
  570.    local A,B,C,D,E,F,G,H = tSHA1.byte_to_bits(b)\\\
  571.    local a,b,c,d,e,f,g,h = tSHA1.byte_to_bits(a)\\\
  572.    return tSHA1.bits_to_byte(\\\
  573.        A and a, B and b, C and c, D and d,\\\
  574.        E and e, F and f, G and g, H and h)\\\
  575. end\\\
  576. tSHA1[\\\"bor\\\"] = function(a,b)\\\
  577.    local A,B,C,D,E,F,G,H = tSHA1.byte_to_bits(b)\\\
  578.    local a,b,c,d,e,f,g,h = tSHA1.byte_to_bits(a)\\\
  579.    return tSHA1.bits_to_byte(\\\
  580.        A or a, B or b, C or c, D or d,\\\
  581.        E or e, F or f, G or g, H or h)\\\
  582. end\\\
  583. tSHA1[\\\"bxor\\\"] = function(a,b)\\\
  584.    local A,B,C,D,E,F,G,H = tSHA1.byte_to_bits(b)\\\
  585.    local a,b,c,d,e,f,g,h = tSHA1.byte_to_bits(a)\\\
  586.    return tSHA1.bits_to_byte(\\\
  587.        A ~= a, B ~= b, C ~= c, D ~= d,\\\
  588.        E ~= e, F ~= f, G ~= g, H ~= h)\\\
  589. end\\\
  590. tSHA1[\\\"bnot\\\"] = function(x) return 255-(x % 256) end\\\
  591. tSHA1[\\\"w32_comb\\\"] = function(fn)\\\
  592.    return function (a,b)\\\
  593.        local aa,ab,ac,ad = tSHA1.w32_to_bytes(a)\\\
  594.        local ba,bb,bc,bd = tSHA1.w32_to_bytes(b)\\\
  595.        return tSHA1.bytes_to_w32(fn(aa,ba),fn(ab,bb),fn(ac,bc),fn(ad,bd))\\\
  596.    end\\\
  597. end\\\
  598. tSHA1[\\\"w32_xor_n\\\"] = function(a,...)\\\
  599.    local aa,ab,ac,ad = tSHA1.w32_to_bytes(a)\\\
  600.    for i=1,select('#',...) do\\\
  601.        local ba,bb,bc,bd = tSHA1.w32_to_bytes(select(i,...))\\\
  602.        aa,ab,ac,ad = tSHA1.bxor(aa,ba),tSHA1.bxor(ab,bb),tSHA1.bxor(ac,bc),tSHA1.bxor(ad,bd)\\\
  603.    end\\\
  604.    return tSHA1.bytes_to_w32(aa,ab,ac,ad)\\\
  605. end\\\
  606. tSHA1[\\\"w32_or3\\\"] = function(a,b,c)\\\
  607.    local aa,ab,ac,ad = tSHA1.w32_to_bytes(a)\\\
  608.    local ba,bb,bc,bd = tSHA1.w32_to_bytes(b)\\\
  609.    local ca,cb,cc,cd = tSHA1.w32_to_bytes(c)\\\
  610.    return tSHA1.bytes_to_w32(\\\
  611.        tSHA1.bor(aa,tSHA1.bor(ba,ca)), tSHA1.bor(ab,tSHA1.bor(bb,cb)), tSHA1.bor(ac,tSHA1.bor(bc,cc)), tSHA1.bor(ad,tSHA1.bor(bd,cd))\\\
  612.    )\\\
  613. end\\\
  614. tSHA1[\\\"w32_not\\\"] = function(a) return 4294967295-(a % 4294967296) end\\\
  615. tSHA1[\\\"w32_add\\\"] = function(a,b) return (a+b) % 4294967296 end\\\
  616. tSHA1[\\\"w32_add_n\\\"] = function(a,...)\\\
  617.    for i=1,select('#',...) do\\\
  618.        a = (a+select(i,...)) % 4294967296\\\
  619.    end\\\
  620.    return a\\\
  621. end\\\
  622. tSHA1[\\\"w32_to_hexstring\\\"] = function(w) return format(\\\"%08x\\\",w) end\\\
  623. tSHA1[\\\"w32_and\\\"] = tSHA1.w32_comb(tSHA1.band)\\\
  624. tSHA1[\\\"w32_xor\\\"] = tSHA1.w32_comb(tSHA1.bxor)\\\
  625. tSHA1[\\\"w32_or\\\"] = tSHA1.w32_comb(tSHA1.bor)\\\
  626. \\\
  627. local CRC = {}\\\
  628. CRC.crc32 = {\\\
  629.    0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,\\\
  630.    0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,\\\
  631.    0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,\\\
  632.    0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,\\\
  633.    0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,\\\
  634.    0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,\\\
  635.    0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,\\\
  636.    0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,\\\
  637.    0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,\\\
  638.    0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,\\\
  639.    0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106,\\\
  640.    0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,\\\
  641.    0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,\\\
  642.    0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,\\\
  643.    0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,\\\
  644.    0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,\\\
  645.    0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,\\\
  646.    0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,\\\
  647.    0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA,\\\
  648.    0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,\\\
  649.    0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,\\\
  650.    0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,\\\
  651.    0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84,\\\
  652.    0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,\\\
  653.    0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,\\\
  654.    0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,\\\
  655.    0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,\\\
  656.    0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,\\\
  657.    0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,\\\
  658.    0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,\\\
  659.    0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28,\\\
  660.    0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,\\\
  661.    0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,\\\
  662.    0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,\\\
  663.    0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,\\\
  664.    0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,\\\
  665.    0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,\\\
  666.    0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,\\\
  667.    0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,\\\
  668.    0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,\\\
  669.    0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,\\\
  670.    0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,\\\
  671.    0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D }\\\
  672. \\\
  673. local bit = {}\\\
  674. bit[\\\"bnot\\\"] = function(n)\\\
  675.    local tbl = bit.tobits(n)\\\
  676.    local size = math.max(table.getn(tbl), 32)\\\
  677.    for i = 1, size do\\\
  678.        if(tbl[i] == 1) then\\\
  679.            tbl[i] = 0\\\
  680.        else\\\
  681.            tbl[i] = 1\\\
  682.        end\\\
  683.    end\\\
  684.    return bit.tonumb(tbl)\\\
  685. end\\\
  686. bit[\\\"band\\\"] = function(m, n)\\\
  687.    local tbl_m = bit.tobits(m)\\\
  688.    local tbl_n = bit.tobits(n)\\\
  689.    bit.expand(tbl_m, tbl_n)\\\
  690.    local tbl = {}\\\
  691.    local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))\\\
  692.    for i = 1, rslt do\\\
  693.        if(tbl_m[i]== 0 or tbl_n[i] == 0) then\\\
  694.            tbl[i] = 0\\\
  695.        else\\\
  696.            tbl[i] = 1\\\
  697.        end\\\
  698.    end\\\
  699.    return bit.tonumb(tbl)\\\
  700. end\\\
  701. bit[\\\"bor\\\"] = function(m, n)\\\
  702.    local tbl_m = bit.tobits(m)\\\
  703.    local tbl_n = bit.tobits(n)\\\
  704.    bit.expand(tbl_m, tbl_n)\\\
  705.    local tbl = {}\\\
  706.    local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))\\\
  707.    for i = 1, rslt do\\\
  708.        if(tbl_m[i]== 0 and tbl_n[i] == 0) then\\\
  709.            tbl[i] = 0\\\
  710.        else\\\
  711.            tbl[i] = 1\\\
  712.        end\\\
  713.    end\\\
  714.    return bit.tonumb(tbl)\\\
  715. end\\\
  716. bit[\\\"bxor\\\"] = function(m, n)\\\
  717.    local tbl_m = bit.tobits(m)\\\
  718.    local tbl_n = bit.tobits(n)\\\
  719.    bit.expand(tbl_m, tbl_n)\\\
  720.    local tbl = {}\\\
  721.    local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))\\\
  722.    for i = 1, rslt do\\\
  723.        if(tbl_m[i] ~= tbl_n[i]) then\\\
  724.            tbl[i] = 1\\\
  725.        else\\\
  726.            tbl[i] = 0\\\
  727.        end\\\
  728.    end\\\
  729.    return bit.tonumb(tbl)\\\
  730. end\\\
  731. bit[\\\"brshift\\\"] = function(n, bits)\\\
  732.    bit.checkint(n)\\\
  733.    local high_bit = 0\\\
  734.    if(n < 0) then\\\
  735.        n = bit.bnot(math.abs(n)) + 1\\\
  736.        high_bit = 2147483648\\\
  737.    end\\\
  738.    for i=1, bits do\\\
  739.        n = n/2\\\
  740.        n = bit.bor(math.floor(n), high_bit)\\\
  741.    end\\\
  742.    return math.floor(n)\\\
  743. end\\\
  744. bit[\\\"blshift\\\"] = function(n, bits)\\\
  745.    bit.checkint(n)\\\
  746.    if(n < 0) then\\\
  747.        n = bit.bnot(math.abs(n)) + 1\\\
  748.    end\\\
  749.    for i=1, bits do\\\
  750.        n = n*2\\\
  751.    end\\\
  752.    return bit.band(n, 4294967295)\\\
  753. end\\\
  754. bit[\\\"bxor2\\\"] = function(m, n)\\\
  755.    local rhs = bit.bor(bit.bnot(m), bit.bnot(n))\\\
  756.    local lhs = bit.bor(m, n)\\\
  757.    local rslt = bit.band(lhs, rhs)\\\
  758.    return rslt\\\
  759. end\\\
  760. bit[\\\"blogic_rshift\\\"] = function(n, bits)\\\
  761.    bit.checkint(n)\\\
  762.    if(n < 0) then\\\
  763.        n = bit.bnot(math.abs(n)) + 1\\\
  764.    end\\\
  765.    for i=1, bits do\\\
  766.        n = n/2\\\
  767.    end\\\
  768.    return math.floor(n)\\\
  769. end\\\
  770. bit[\\\"tobits\\\"] = function(n)\\\
  771.    bit.checkint(n)\\\
  772.    if(n < 0) then\\\
  773.        return bit.tobits(bit.bnot(math.abs(n)) + 1)\\\
  774.    end\\\
  775.    local tbl = {}\\\
  776.    local cnt = 1\\\
  777.    while (n > 0) do\\\
  778.        local last = math.fmod(n,2)\\\
  779.        if(last == 1) then\\\
  780.            tbl[cnt] = 1\\\
  781.        else\\\
  782.            tbl[cnt] = 0\\\
  783.        end\\\
  784.        n = (n-last)/2\\\
  785.        cnt = cnt + 1\\\
  786.    end\\\
  787.    return tbl\\\
  788. end\\\
  789. bit[\\\"tonumb\\\"] = function(tbl)\\\
  790.    local n = table.getn(tbl)\\\
  791.    local rslt = 0\\\
  792.    local power = 1\\\
  793.    for i = 1, n do\\\
  794.        rslt = rslt + tbl[i]*power\\\
  795.        power = power*2\\\
  796.    end\\\
  797.    return rslt\\\
  798. end\\\
  799. bit[\\\"checkint\\\"] = function(n)\\\
  800.    if(n - math.floor(n) > 0) then\\\
  801.        error(\\\"trying to use bitwise operation on non-integer!\\\")\\\
  802.    end\\\
  803. end\\\
  804. bit[\\\"expand\\\"] = function(tbl_m, tbl_n)\\\
  805.    local big = {}\\\
  806.    local small = {}\\\
  807.    if(table.getn(tbl_m) > table.getn(tbl_n)) then\\\
  808.        big = tbl_m\\\
  809.        small = tbl_n\\\
  810.    else\\\
  811.        big = tbl_n\\\
  812.        small = tbl_m\\\
  813.    end\\\
  814.    for i = table.getn(small) + 1, table.getn(big) do\\\
  815.        small[i] = 0\\\
  816.    end\\\
  817. end\\\
  818. \\\
  819. local FCS = {}\\\
  820. FCS[\\\"16\\\"] = {\\\
  821.    [0]=0, 4489, 8978, 12955, 17956, 22445, 25910, 29887,\\\
  822.    35912, 40385, 44890, 48851, 51820, 56293, 59774, 63735,\\\
  823.    4225, 264, 13203, 8730, 22181, 18220, 30135, 25662,\\\
  824.    40137, 36160, 49115, 44626, 56045, 52068, 63999, 59510,\\\
  825.    8450, 12427, 528, 5017, 26406, 30383, 17460, 21949,\\\
  826.    44362, 48323, 36440, 40913, 60270, 64231, 51324, 55797,\\\
  827.    12675, 8202, 4753, 792, 30631, 26158, 21685, 17724,\\\
  828.    48587, 44098, 40665, 36688, 64495, 60006, 55549, 51572,\\\
  829.    16900, 21389, 24854, 28831, 1056, 5545, 10034, 14011,\\\
  830.    52812, 57285, 60766, 64727, 34920, 39393, 43898, 47859,\\\
  831.    21125, 17164, 29079, 24606, 5281, 1320, 14259, 9786,\\\
  832.    57037, 53060, 64991, 60502, 39145, 35168, 48123, 43634,\\\
  833.    25350, 29327, 16404, 20893, 9506, 13483, 1584, 6073,\\\
  834.    61262, 65223, 52316, 56789, 43370, 47331, 35448, 39921,\\\
  835.    29575, 25102, 20629, 16668, 13731, 9258, 5809, 1848,\\\
  836.    65487, 60998, 56541, 52564, 47595, 43106, 39673, 35696,\\\
  837.    33800, 38273, 42778, 46739, 49708, 54181, 57662, 61623,\\\
  838.    2112, 6601, 11090, 15067, 20068, 24557, 28022, 31999,\\\
  839.    38025, 34048, 47003, 42514, 53933, 49956, 61887, 57398,\\\
  840.    6337, 2376, 15315, 10842, 24293, 20332, 32247, 27774,\\\
  841.    42250, 46211, 34328, 38801, 58158, 62119, 49212, 53685,\\\
  842.    10562, 14539, 2640, 7129, 28518, 32495, 19572, 24061,\\\
  843.    46475, 41986, 38553, 34576, 62383, 57894, 53437, 49460,\\\
  844.    14787, 10314, 6865, 2904, 32743, 28270, 23797, 19836,\\\
  845.    50700, 55173, 58654, 62615, 32808, 37281, 41786, 45747,\\\
  846.    19012, 23501, 26966, 30943, 3168, 7657, 12146, 16123,\\\
  847.    54925, 50948, 62879, 58390, 37033, 33056, 46011, 41522,\\\
  848.    23237, 19276, 31191, 26718, 7393, 3432, 16371, 11898,\\\
  849.    59150, 63111, 50204, 54677, 41258, 45219, 33336, 37809,\\\
  850.    27462, 31439, 18516, 23005, 11618, 15595, 3696, 8185,\\\
  851.    63375, 58886, 54429, 50452, 45483, 40994, 37561, 33584,\\\
  852.    31687, 27214, 22741, 18780, 15843, 11370, 7921, 3960 }\\\
  853. FCS[\\\"32\\\"] = {\\\
  854.    [0]=0, 1996959894, -301047508, -1727442502, 124634137, 1886057615, -379345611, -1637575261,\\\
  855.    249268274, 2044508324, -522852066, -1747789432, 162941995, 2125561021, -407360249, -1866523247,\\\
  856.    498536548, 1789927666, -205950648, -2067906082, 450548861, 1843258603, -187386543, -2083289657,\\\
  857.    325883990, 1684777152, -43845254, -1973040660, 335633487, 1661365465, -99664541, -1928851979,\\\
  858.    997073096, 1281953886, -715111964, -1570279054, 1006888145, 1258607687, -770865667, -1526024853,\\\
  859.    901097722, 1119000684, -608450090, -1396901568, 853044451, 1172266101, -589951537, -1412350631,\\\
  860.    651767980, 1373503546, -925412992, -1076862698, 565507253, 1454621731, -809855591, -1195530993,\\\
  861.    671266974, 1594198024, -972236366, -1324619484, 795835527, 1483230225, -1050600021, -1234817731,\\\
  862.    1994146192, 31158534, -1731059524, -271249366, 1907459465, 112637215, -1614814043, -390540237,\\\
  863.    2013776290, 251722036, -1777751922, -519137256, 2137656763, 141376813, -1855689577, -429695999,\\\
  864.    1802195444, 476864866, -2056965928, -228458418, 1812370925, 453092731, -2113342271, -183516073,\\\
  865.    1706088902, 314042704, -1950435094, -54949764, 1658658271, 366619977, -1932296973, -69972891,\\\
  866.    1303535960, 984961486, -1547960204, -725929758, 1256170817, 1037604311, -1529756563, -740887301,\\\
  867.    1131014506, 879679996, -1385723834, -631195440, 1141124467, 855842277, -1442165665, -586318647,\\\
  868.    1342533948, 654459306, -1106571248, -921952122, 1466479909, 544179635, -1184443383, -832445281,\\\
  869.    1591671054, 702138776, -1328506846, -942167884, 1504918807, 783551873, -1212326853, -1061524307,\\\
  870.    -306674912, -1698712650, 62317068, 1957810842, -355121351, -1647151185, 81470997, 1943803523,\\\
  871.    -480048366, -1805370492, 225274430, 2053790376, -468791541, -1828061283, 167816743, 2097651377,\\\
  872.    -267414716, -2029476910, 503444072, 1762050814, -144550051, -2140837941, 426522225, 1852507879,\\\
  873.    -19653770, -1982649376, 282753626, 1742555852, -105259153, -1900089351, 397917763, 1622183637,\\\
  874.    -690576408, -1580100738, 953729732, 1340076626, -776247311, -1497606297, 1068828381, 1219638859,\\\
  875.    -670225446, -1358292148, 906185462, 1090812512, -547295293, -1469587627, 829329135, 1181335161,\\\
  876.    -882789492, -1134132454, 628085408, 1382605366, -871598187, -1156888829, 570562233, 1426400815,\\\
  877.    -977650754, -1296233688, 733239954, 1555261956, -1026031705, -1244606671, 752459403, 1541320221,\\\
  878.    -1687895376, -328994266, 1969922972, 40735498, -1677130071, -351390145, 1913087877, 83908371,\\\
  879.    -1782625662, -491226604, 2075208622, 213261112, -1831694693, -438977011, 2094854071, 198958881,\\\
  880.    -2032938284, -237706686, 1759359992, 534414190, -2118248755, -155638181, 1873836001, 414664567,\\\
  881.    -2012718362, -15766928, 1711684554, 285281116, -1889165569, -127750551, 1634467795, 376229701,\\\
  882.    -1609899400, -686959890, 1308918612, 956543938, -1486412191, -799009033, 1231636301, 1047427035,\\\
  883.    -1362007478, -640263460, 1088359270, 936918000, -1447252397, -558129467, 1202900863, 817233897,\\\
  884.    -1111625188, -893730166, 1404277552, 615818150, -1160759803, -841546093, 1423857449, 601450431,\\\
  885.    -1285129682, -1000256840, 1567103746, 711928724, -1274298825, -1022587231, 1510334235, 755167117 }\\\
  886. \\\
  887. --String Utils :\\\
  888. \\\
  889. function toCharTable(str)  --Returns table of @str's chars\\\
  890.    if not str then return nil end\\\
  891.    str = tostring(str)\\\
  892.     local chars = {}\\\
  893.     for n=1,#str do\\\
  894.         chars[n] = str:sub(n,n)\\\
  895.     end\\\
  896.     return chars\\\
  897. end\\\
  898. \\\
  899. function toByteTable(str)  --Returns table of @str's bytes\\\
  900.    if not str then return nil end\\\
  901.    str = tostring(str)\\\
  902.     local bytes = {}\\\
  903.     for n=1,#str do\\\
  904.         bytes[n] = str:byte(n)\\\
  905.     end\\\
  906.     return bytes\\\
  907. end\\\
  908. \\\
  909. function fromCharTable(chars)  --Returns string made of chracters in @chars\\\
  910.    if not chars or type(chars)~=\\\"table\\\" then return nil end\\\
  911.     return table.concat(chars)\\\
  912. end\\\
  913. \\\
  914. function fromByteTable(bytes)  --Returns string made of bytes in @bytes\\\
  915.    if not bytes or type(bytes)~=\\\"table\\\" then return nil end\\\
  916.     local str = \\\"\\\"\\\
  917.     for n=1,#bytes do\\\
  918.         str = str..string.char(bytes[n])\\\
  919.     end\\\
  920.     return str\\\
  921. end\\\
  922. \\\
  923. function contains(str,find)  --Returns true if @str contains @find\\\
  924.    if not str then return nil end\\\
  925.    str = tostring(str)\\\
  926.     for n=1, #str-#find+1 do\\\
  927.         if str:sub(n,n+#find-1) == find then return true end\\\
  928.     end\\\
  929.     return false\\\
  930. end\\\
  931. \\\
  932. function startsWith(str,Start) --Check if @str starts with @Start\\\
  933.    if not str then return nil end\\\
  934.    str = tostring(str)\\\
  935.    return str:sub(1,Start:len())==Start\\\
  936. end\\\
  937. \\\
  938. function endsWith(str,End)  --Check if @str ends with @End\\\
  939.    if not str then return nil end\\\
  940.    str = tostring(str)\\\
  941.    return End=='' or str:sub(#str-#End+1)==End\\\
  942. end\\\
  943. \\\
  944. function trim(str)  --Trim @str of initial/trailing whitespace\\\
  945.    if not str then return nil end\\\
  946.    str = tostring(str)\\\
  947.    return (str:gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\"))\\\
  948. end\\\
  949. \\\
  950. function firstLetterUpper(str)  --Capitilizes first letter of @str\\\
  951.    if not str then return nil end\\\
  952.    str = tostring(str)\\\
  953.     str = str:gsub(\\\"%a\\\", string.upper, 1)\\\
  954.    return str\\\
  955. end\\\
  956. \\\
  957. function titleCase(str)  --Changes @str to title case\\\
  958.     if not str then return nil end\\\
  959.     str = tostring(str)\\\
  960.    local function tchelper(first, rest)\\\
  961.         return first:upper()..rest:lower()\\\
  962.    end\\\
  963.    str = str:gsub(\\\"(%a)([%w_']*)\\\", tchelper)\\\
  964.     return str\\\
  965. end\\\
  966. \\\
  967. function isRepetition(str, pat)  --Checks if @str is a repetition of @pat\\\
  968.    if not str then return nil end\\\
  969.    str = tostring(str)\\\
  970.     return \\\"\\\" == str:gsub(pat, \\\"\\\")\\\
  971. end\\\
  972. \\\
  973. function isRepetitionWS(str, pat)  --Checks if @str is a repetition of @pat seperated by whitespaces\\\
  974.    if not str then return nil end\\\
  975.    str = tostring(str)\\\
  976.     return not str:gsub(pat, \\\"\\\"):find\\\"%S\\\"\\\
  977. end\\\
  978. \\\
  979. function urlDecode(str)  --Url decodes @str\\\
  980.    if not str then return nil end\\\
  981.    str = tostring(str)\\\
  982.     str = string.gsub (str, \\\"+\\\", \\\" \\\")\\\
  983.     str = string.gsub (str, \\\"%%(%x%x)\\\", function(h) return string.char(tonumber(h,16)) end)\\\
  984.     str = string.gsub (str, \\\"\\\\r\\\\n\\\", \\\"\\\\n\\\")\\\
  985.     return str\\\
  986. end\\\
  987. \\\
  988. function urlEncode(str)  --Url encodes @str\\\
  989.    if not str then return nil end\\\
  990.    str = tostring(str)\\\
  991.     if (str) then\\\
  992.         str = string.gsub (str, \\\"\\\\n\\\", \\\"\\\\r\\\\n\\\")\\\
  993.         str = string.gsub (str, \\\"([^%w ])\\\", function (c) return string.format (\\\"%%%02X\\\", string.byte(c)) end)\\\
  994.         str = string.gsub (str, \\\" \\\", \\\"+\\\")\\\
  995.     end\\\
  996.     return str\\\
  997. end\\\
  998. \\\
  999. function isEmailAddress(str)  --Checks if @str is a valid email address\\\
  1000.    if not str then return nil end\\\
  1001.    str = tostring(str)\\\
  1002.     if (str:match(\\\"[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?\\\")) then\\\
  1003.         return true\\\
  1004.     else\\\
  1005.         return false\\\
  1006.     end\\\
  1007. end\\\
  1008. \\\
  1009. function chunk(str, size)  --Splits @str into chunks of length @size\\\
  1010.     if not size then return nil end\\\
  1011.     str = tostring(str)\\\
  1012.     local num2App = size - (#str%size)\\\
  1013.     str = str..(rep(char(0), num2App) or \\\"\\\")\\\
  1014.     assert(#str%size==0)\\\
  1015.     local chunks = {}\\\
  1016.     local numChunks = #str / size\\\
  1017.     local chunk = 0\\\
  1018.     while chunk < numChunks do\\\
  1019.         local start = chunk * size + 1\\\
  1020.        chunk = chunk+1\\\
  1021.         if start+size-1 > #str-num2App then\\\
  1022.            if str:sub(start, #str-num2App) ~= (nil or \\\"\\\") then\\\
  1023.                 chunks[chunk] = str:sub(start, #str-num2App)\\\
  1024.            end\\\
  1025.         else\\\
  1026.             chunks[chunk] = str:sub(start, start+size-1)\\\
  1027.         end\\\
  1028.     end\\\
  1029.     return chunks\\\
  1030. end\\\
  1031. \\\
  1032. function find(str, match, startIndex)  --Finds @match in @str optionally after @startIndex\\\
  1033.     if not match then return nil end\\\
  1034.     str = tostring(str)\\\
  1035.     local _ = startIndex or 1\\\
  1036.     local _s = nil\\\
  1037.     local _e = nil\\\
  1038.     local _len = match:len()\\\
  1039.     while true do\\\
  1040.         local _t = str:sub( _ , _len + _ - 1)\\\
  1041.         if _t == match then\\\
  1042.             _s = _\\\
  1043.             _e = _ + _len - 1\\\
  1044.             break\\\
  1045.         end\\\
  1046.         _ = _ + 1\\\
  1047.         if _ > str:len() then break end\\\
  1048.     end\\\
  1049.     if _s == nil then return nil else return _s, _e end\\\
  1050. end\\\
  1051. \\\
  1052. function seperate(str, divider)  --Separates @str on @divider\\\
  1053.     if not divider then return nil end\\\
  1054.     str = tostring(str)\\\
  1055.     local start = {}\\\
  1056.     local endS = {}\\\
  1057.     local n=1\\\
  1058.     repeat\\\
  1059.         if n==1 then\\\
  1060.             start[n], endS[n] = find(str, divider)\\\
  1061.         else\\\
  1062.             start[n], endS[n] = find(str, divider, endS[n-1]+1)\\\
  1063.        end\\\
  1064.         n=n+1\\\
  1065.     until start[n-1]==nil\\\
  1066.     local subs = {}\\\
  1067.     for n=1, #start+1 do\\\
  1068.         if n==1 then\\\
  1069.             subs[n] = str:sub(1, start[n]-1)\\\
  1070.         elseif n==#start+1 then\\\
  1071.             subs[n] = str:sub(endS[n-1]+1)\\\
  1072.         else\\\
  1073.             subs[n] = str:sub(endS[n-1]+1, start[n]-1)\\\
  1074.        end\\\
  1075.     end\\\
  1076.     return subs\\\
  1077. end\\\
  1078. \\\
  1079. function replace(str, from, to)  --Replaces @from to @to in @str\\\
  1080.     if not from then return nil end\\\
  1081.     str = tostring(str)\\\
  1082.     local pcs = seperate(str, from)\\\
  1083.     str = pcs[1]\\\
  1084.     for n=2,#pcs do\\\
  1085.         str = str..to..pcs[n]\\\
  1086.     end\\\
  1087.     return str\\\
  1088. end\\\
  1089. \\\
  1090. function jumble(str)  --Jumbles @str\\\
  1091.     if not str then return nil end\\\
  1092.     str = tostring(str)\\\
  1093.     local chars = {}\\\
  1094.     for i = 1, #str do\\\
  1095.         chars[i] = str:sub(i, i)\\\
  1096.     end\\\
  1097.     local usedNums = \\\":\\\"\\\
  1098.     local res = \\\"\\\"\\\
  1099.     local rand = 0\\\
  1100.     for i=1, #chars do\\\
  1101.         while true do\\\
  1102.             rand = math.random(#chars)\\\
  1103.             if find(usedNums, \\\":\\\"..rand..\\\":\\\") == nil then break end\\\
  1104.         end\\\
  1105.         res = res..chars[rand]\\\
  1106.         usedNums = usedNums..rand..\\\":\\\"\\\
  1107.     end\\\
  1108.     return res\\\
  1109. end\\\
  1110. \\\
  1111. function toBase(str, base)  --Encodes @str in @base\\\
  1112.     if not base then return nil end\\\
  1113.     str = tostring(str)\\\
  1114.     local res = \\\"\\\"\\\
  1115.     for i = 1, str:len() do\\\
  1116.         if i == 1 then\\\
  1117.             res = basen(str:byte(i), base)\\\
  1118.         else\\\
  1119.             res = res..\\\":\\\"..basen(str:byte(i), base)\\\
  1120.         end\\\
  1121.     end\\\
  1122.     return res\\\
  1123. end\\\
  1124. \\\
  1125. function fromBase(str, base)  --Decodes @str from @base\\\
  1126.     if not base then return nil end\\\
  1127.     str = tostring(str)\\\
  1128.     local bytes = seperate(str, \\\":\\\")\\\
  1129.     local res = \\\"\\\"\\\
  1130.     for i = 1, #bytes do\\\
  1131.         res = res..(string.char(basen(tonumber(bytes[i], base), 10)))\\\
  1132.     end\\\
  1133.     return res\\\
  1134. end\\\
  1135. \\\
  1136. function toBinary(str)  --Encodes @str in binary\\\
  1137.     if not str then return nil end\\\
  1138.     str = tostring(str)\\\
  1139.     return toBase(str, 2)\\\
  1140. end\\\
  1141. \\\
  1142. function fromBinary(str)  --Decodes @str from binary\\\
  1143.     if not str then return nil end\\\
  1144.     str = tostring(str)\\\
  1145.     return fromBase(str, 2)\\\
  1146. end\\\
  1147. \\\
  1148. function toOctal(str)  --Encodes @str in octal\\\
  1149.     if not str then return nil end\\\
  1150.     str = tostring(str)\\\
  1151.     return toBase(str, 8)\\\
  1152. end\\\
  1153. \\\
  1154. function fromOctal(str)  --Decodes @str from octal\\\
  1155.     if not str then return nil end\\\
  1156.     str = tostring(str)\\\
  1157.     return fromBase(str, 8)\\\
  1158. end\\\
  1159. \\\
  1160. function toHex(str)  --Encodes @str in hex\\\
  1161.     if not str then return nil end\\\
  1162.     str = tostring(str)\\\
  1163.     return toBase(str, 16)\\\
  1164. end\\\
  1165. \\\
  1166. function fromHex(str)  --Decodes @str from hex\\\
  1167.     if not str then return nil end\\\
  1168.     str = tostring(str)\\\
  1169.     return fromBase(str, 16)\\\
  1170. end\\\
  1171. \\\
  1172. function toBase36(str)  --Encodes @str in Base36\\\
  1173.     if not str then return nil end\\\
  1174.     str = tostring(str)\\\
  1175.     return toBase(str, 36)\\\
  1176. end\\\
  1177. \\\
  1178. function fromBase36(str)  --Decodes @str from Base36\\\
  1179.     if not str then return nil end\\\
  1180.     str = tostring(str)\\\
  1181.     return fromBase(str, 36)\\\
  1182. end\\\
  1183. \\\
  1184. function toBase32(str)  --Encodes @str in Base32\\\
  1185.     if not str then return nil end\\\
  1186.     str = tostring(str)\\\
  1187.     local byte=0\\\
  1188.     local bits=0\\\
  1189.     local rez=\\\"\\\"\\\
  1190.     local i=0\\\
  1191.     for i = 1, str:len() do\\\
  1192.         byte=byte*256+str:byte(i)\\\
  1193.         bits=bits+8\\\
  1194.         repeat\\\
  1195.             bits=bits-5\\\
  1196.             local mul=(2^(bits))\\\
  1197.             local b32n=math.floor(byte/mul)\\\
  1198.             byte=byte-(b32n*mul)\\\
  1199.             b32n=b32n+1\\\
  1200.             rez=rez..string.sub(base32,b32n,b32n)\\\
  1201.         until bits<5\\\
  1202.     end\\\
  1203.     if bits>0 then\\\
  1204.         local b32n= math.fmod(byte*(2^(5-bits)),32)\\\
  1205.         b32n=b32n+1\\\
  1206.         rez=rez..string.sub(base32,b32n,b32n)\\\
  1207.     end\\\
  1208.     return rez\\\
  1209. end\\\
  1210. \\\
  1211. function fromBase32(str)  --Decodes @str from Base32\\\
  1212.     if not str then return nil end\\\
  1213.     str = tostring(str)\\\
  1214.     local b32n=0\\\
  1215.     local bits=0\\\
  1216.     local rez=\\\"\\\"\\\
  1217.     local i=0\\\
  1218.     string.gsub(str:upper(), \\\"[\\\"..base32..\\\"]\\\", function (char)\\\
  1219.         local num = string.find(base32, char, 1, true)\\\
  1220.         b32n=b32n*32+(num - 1)\\\
  1221.         bits=bits+5\\\
  1222.         while  bits>=8 do\\\
  1223.             bits=bits-8\\\
  1224.             local mul=(2^(bits))\\\
  1225.             local byte = math.floor(b32n/mul)\\\
  1226.             b32n=b32n-(byte*mul)\\\
  1227.             rez=rez..string.char(byte)\\\
  1228.         end\\\
  1229.     end)\\\
  1230.     return rez\\\
  1231. end\\\
  1232. \\\
  1233. function toBase64(str)  --Encodes @str in Base64\\\
  1234.     if not str then return nil end\\\
  1235.     str = tostring(str)\\\
  1236.     local bytes = {}\\\
  1237.     local result = \\\"\\\"\\\
  1238.     for spos=0,str:len()-1,3 do\\\
  1239.         for byte=1,3 do bytes[byte] = str:byte(spos+byte) or 0 end\\\
  1240.         result = string.format('%s%s%s%s%s',result,Base64.base64chars[Base64.rsh(bytes[1],2)],Base64.base64chars[Base64.lor(Base64.lsh((bytes[1] % 4),4), Base64.rsh(bytes[2],4))] or \\\"=\\\",((str:len()-spos) > 1) and Base64.base64chars[Base64.lor(Base64.lsh(bytes[2] % 16,2), Base64.rsh(bytes[3],6))] or \\\"=\\\",((str:len()-spos) > 2) and Base64.base64chars[(bytes[3] % 64)] or \\\"=\\\")\\\
  1241.     end\\\
  1242.     return result\\\
  1243. end\\\
  1244. \\\
  1245. function fromBase64(str)  --Decodes @str from Base64\\\
  1246.     if not str then return nil end\\\
  1247.     str = tostring(str)\\\
  1248.     local chars = {}\\\
  1249.     local result=\\\"\\\"\\\
  1250.     for dpos=0,str:len()-1,4 do\\\
  1251.         for char=1,4 do chars[char] = Base64.base64bytes[(str:sub((dpos+char),(dpos+char)) or \\\"=\\\")] end\\\
  1252.         result = string.format('%s%s%s%s',result,string.char(Base64.lor(Base64.lsh(chars[1],2), Base64.rsh(chars[2],4))),(chars[3] ~= nil) and string.char(Base64.lor(Base64.lsh(chars[2],4), Base64.rsh(chars[3],2))) or \\\"\\\",(chars[4] ~= nil) and string.char(Base64.lor(Base64.lsh(chars[3],6) % 192, (chars[4]))) or \\\"\\\")\\\
  1253.     end\\\
  1254.     return result\\\
  1255. end\\\
  1256. \\\
  1257. function rot13(str)  --Rot13s @str\\\
  1258.     if not str then return nil end\\\
  1259.     str = tostring(str)\\\
  1260.     local rot = \\\"\\\"\\\
  1261.     local len = str:len()\\\
  1262.     for i = 1, len do\\\
  1263.         local k = str:byte(i)\\\
  1264.         if (k >= 65 and k <= 77) or (k >= 97 and k <=109) then\\\
  1265.             rot = rot..string.char(k+13)\\\
  1266.         elseif (k >= 78 and k <= 90) or (k >= 110 and k <= 122) then\\\
  1267.             rot = rot..string.char(k-13)\\\
  1268.         else\\\
  1269.             rot = rot..string.char(k)\\\
  1270.         end\\\
  1271.     end\\\
  1272.     return rot\\\
  1273. end\\\
  1274. \\\
  1275. function rot47(str)  --Rot47s @str\\\
  1276.     if not str then return nil end\\\
  1277.     str = tostring(str)\\\
  1278.     local rot = \\\"\\\"\\\
  1279.     for i = 1, str:len() do\\\
  1280.         local p = str:byte(i)\\\
  1281.         if p >= string.byte('!') and p <= string.byte('O') then\\\
  1282.             p = ((p + 47) % 127)\\\
  1283.         elseif p >= string.byte('P') and p <= string.byte('~') then\\\
  1284.             p = ((p - 47) % 127)\\\
  1285.         end\\\
  1286.         rot = rot..string.char(p)\\\
  1287.     end\\\
  1288.     return rot\\\
  1289. end\\\
  1290. \\\
  1291. function SHA1(str) --Returns SHA1 Hash of @str\\\
  1292.    if not str then return nil end\\\
  1293.    str = tostring(str)\\\
  1294.    local H0,H1,H2,H3,H4 = 0x67452301,0xEFCDAB89,0x98BADCFE,0x10325476,0xC3D2E1F0\\\
  1295.    local msg_len_in_bits = #str * 8\\\
  1296.    local first_append = char(0x80)\\\
  1297.    local non_zero_message_bytes = #str +1 +8\\\
  1298.    local current_mod = non_zero_message_bytes % 64\\\
  1299.    local second_append = current_mod>0 and rep(char(0), 64 - current_mod) or \\\"\\\"\\\
  1300.    local B1, R1 = modf(msg_len_in_bits  / 0x01000000)\\\
  1301.    local B2, R2 = modf( 0x01000000 * R1 / 0x00010000)\\\
  1302.    local B3, R3 = modf( 0x00010000 * R2 / 0x00000100)\\\
  1303.     local B4      = 0x00000100 * R3\\\
  1304.    local L64 = char( 0) .. char( 0) .. char( 0) .. char( 0)\\\
  1305.            .. char(B1) .. char(B2) .. char(B3) .. char(B4)\\\
  1306.    str = str .. first_append .. second_append .. L64\\\
  1307.    assert(#str % 64 == 0)\\\
  1308.    local chunks = #str / 64\\\
  1309.    local W = { }\\\
  1310.    local start, A, B, C, D, E, f, K, TEMP\\\
  1311.    local chunk = 0\\\
  1312.    while chunk < chunks do\\\
  1313.        start,chunk = chunk * 64 + 1,chunk + 1\\\
  1314.        for t = 0, 15 do\\\
  1315.            W[t] = tSHA1.bytes_to_w32(str:byte(start, start + 3))\\\
  1316.            start = start + 4\\\
  1317.        end\\\
  1318.        for t = 16, 79 do\\\
  1319.            W[t] = tSHA1.w32_rot(1, tSHA1.w32_xor_n(W[t-3], W[t-8], W[t-14], W[t-16]))\\\
  1320.        end\\\
  1321.        A,B,C,D,E = H0,H1,H2,H3,H4\\\
  1322.        for t = 0, 79 do\\\
  1323.            if t <= 19 then\\\
  1324.                f = tSHA1.w32_or(tSHA1.w32_and(B, C), tSHA1.w32_and(tSHA1.w32_not(B), D))\\\
  1325.                K = 0x5A827999\\\
  1326.            elseif t <= 39 then\\\
  1327.                f = tSHA1.w32_xor_n(B, C, D)\\\
  1328.                K = 0x6ED9EBA1\\\
  1329.            elseif t <= 59 then\\\
  1330.                f = tSHA1.w32_or3(tSHA1.w32_and(B, C), tSHA1.w32_and(B, D), tSHA1.w32_and(C, D))\\\
  1331.                K = 0x8F1BBCDC\\\
  1332.            else\\\
  1333.                f = tSHA1.w32_xor_n(B, C, D)\\\
  1334.                K = 0xCA62C1D6\\\
  1335.            end\\\
  1336.            A,B,C,D,E = tSHA1.w32_add_n(tSHA1.w32_rot(5, A), f, E, W[t], K),\\\
  1337.            A, tSHA1.w32_rot(30, B), C, D\\\
  1338.        end\\\
  1339.        H0,H1,H2,H3,H4 = tSHA1.w32_add(H0, A),tSHA1.w32_add(H1, B),tSHA1.w32_add(H2, C),tSHA1.w32_add(H3, D),tSHA1.w32_add(H4, E)\\\
  1340.    end\\\
  1341.    local f = tSHA1.w32_to_hexstring\\\
  1342.    return f(H0) .. f(H1) .. f(H2) .. f(H3) .. f(H4)\\\
  1343. end\\\
  1344. \\\
  1345. function CRC32(str) --Returns CRC32 Hash of @str\\\
  1346.    local crc, l, i = 0xFFFFFFFF, string.len(str)\\\
  1347.    for i = 1, l, 1 do\\\
  1348.        crc = bit.bxor(bit.brshift(crc, 8), CRC.crc32[bit.band(bit.bxor(crc, string.byte(str, i)), 0xFF) + 1])\\\
  1349.    end\\\
  1350.    return bit.bxor(crc, -1)\\\
  1351. end\\\
  1352. \\\
  1353. function FCS16(str) --Returns FCS16 Hash of @str\\\
  1354.    local i\\\
  1355.    local l=string.len(str)\\\
  1356.    local uFcs16 = 65535\\\
  1357.    for i = 1,l do\\\
  1358.        uFcs16 = bit.bxor(bit.brshift(uFcs16,8), FCS[\\\"16\\\"][bit.band(bit.bxor(uFcs16, string.byte(str,i)), 255)])\\\
  1359.    end\\\
  1360.    return  bit.bxor(uFcs16, 65535)\\\
  1361. end\\\
  1362. \\\
  1363. function FCS32(str) --Returns FCS32 Hash of @str\\\
  1364.    local i\\\
  1365.    local l = string.len(str)\\\
  1366.    local uFcs32 = -1\\\
  1367.    for i=1,l do\\\
  1368.        uFcs32 = bit.bxor(bit.brshift(uFcs32,8), FCS[\\\"32\\\"][bit.band(bit.bxor(uFcs32, string.byte(str,i)), 255)])\\\
  1369.    end\\\
  1370.    return bit.bnot(uFcs32)\\\
  1371. end\\\
  1372. \\\
  1373. function encrypt(str, key)  --Encrypts @str with @key\\\
  1374.     if not key then return nil end\\\
  1375.     str = tostring(str)\\\
  1376.     local alphabet = \\\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_abcdefghijklmnopqrstuvwxyz{|}~\\\"\\\
  1377.     local _rand = math.random(#alphabet-10)\\\
  1378.     local iv = string.sub(jumble(alphabet), _rand, _rand  + 9)\\\
  1379.     iv = jumble(iv)\\\
  1380.     str = iv..str\\\
  1381.     local key = SHA1(key)\\\
  1382.     local strLen = str:len()\\\
  1383.     local keyLen = key:len()\\\
  1384.     local j=1\\\
  1385.     local result = \\\"\\\"\\\
  1386.     for i=1, strLen do\\\
  1387.         local ordStr = string.byte(str:sub(i,i))\\\
  1388.         if j == keyLen then j=1 end\\\
  1389.         local ordKey = string.byte(key:sub(j,j))\\\
  1390.         result = result..string.reverse(basen(ordStr+ordKey, 36))\\\
  1391.         j = j+1\\\
  1392.     end\\\
  1393.     return result\\\
  1394. end\\\
  1395. \\\
  1396. function decrypt(str, key)  --Decrypts @str with @key\\\
  1397.     if not key then return nil end\\\
  1398.     str = tostring(str)\\\
  1399.     local key = SHA1(key)\\\
  1400.     local strLen = str:len()\\\
  1401.     local keyLen = key:len()\\\
  1402.     local j=1\\\
  1403.     local result = \\\"\\\"\\\
  1404.     for i=1, strLen, 2 do\\\
  1405.         local ordStr = basen(tonumber(string.reverse(str:sub(i, i+1)),36),10)\\\
  1406.         if j==keyLen then j=1 end\\\
  1407.         local ordKey = string.byte(key:sub(j,j))\\\
  1408.         result = result..string.char(ordStr-ordKey)\\\
  1409.         j = j+1\\\
  1410.     end\\\
  1411.     return result:sub(11)\\\
  1412. end\\\
  1413. \\\
  1414. function setRandSeed(seed)  --Sets random seed to @seed\\\
  1415.     math.randomseed(seed)\\\
  1416. end\\\
  1417. \\\
  1418. setRandSeed(os.time())\",\
  1419. }"function makeDir(table,dir) if not fs.exists(dir) then fs.makeDir(dir) end for k, v in pairs(table) do if type(v)=='table' then makeDir(v,dir..'/'..k) else local fileH=fs.open(dir..'/'..k,'w') fileH.write(v) fileH.close() end end end tArgs={...} if #tArgs<1 then print('Usage: unpackager <destination>') else makeDir(textutils.unserialize(c),shell.resolve(tArgs[1])) print('Succ: Successfully extracted package') end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement