Advertisement
killer64

Untitled

Jan 4th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. local tob64,unb64,genkey,new,unserialize
  2. do
  3. local _tob64={
  4. [0]="A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
  5. "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
  6. "0","1","2","3","4","5","6","7","8","9","+","/"
  7. }
  8. function tob64(stxt)
  9. local txt=tostring(stxt)
  10. if not txt then
  11. error("string expected, got "..type(stxt),2)
  12. end
  13. local d,o,d1,d2,d3={string.byte(txt,1,#txt)},""
  14. for l1=1,#txt-2,3 do
  15. d1,d2,d3=d[l1],d[l1+1],d[l1+2]
  16. o=o.._tob64[math.floor(d1/4)].._tob64[((d1%4)*16)+math.floor(d2/16)].._tob64[((d2%16)*4)+math.floor(d3/64)].._tob64[d3%64]
  17. end
  18. local m=#txt%3
  19. if m==1 then
  20. o=o.._tob64[math.floor(d[#txt]/4)].._tob64[((d[#txt]%4)*16)].."=="
  21. elseif m==2 then
  22. o=o.._tob64[math.floor(d[#txt-1]/4)].._tob64[((d[#txt-1]%4)*16)+math.floor(d[#txt]/16)].._tob64[(d[#txt]%16)*4].."="
  23. end
  24. return o
  25. end
  26. local _unb64={
  27. ["A"]=0,["B"]=1,["C"]=2,["D"]=3,["E"]=4,["F"]=5,["G"]=6,["H"]=7,["I"]=8,["J"]=9,["K"]=10,["L"]=11,["M"]=12,["N"]=13,
  28. ["O"]=14,["P"]=15,["Q"]=16,["R"]=17,["S"]=18,["T"]=19,["U"]=20,["V"]=21,["W"]=22,["X"]=23,["Y"]=24,["Z"]=25,
  29. ["a"]=26,["b"]=27,["c"]=28,["d"]=29,["e"]=30,["f"]=31,["g"]=32,["h"]=33,["i"]=34,["j"]=35,["k"]=36,["l"]=37,["m"]=38,
  30. ["n"]=39,["o"]=40,["p"]=41,["q"]=42,["r"]=43,["s"]=44,["t"]=45,["u"]=46,["v"]=47,["w"]=48,["x"]=49,["y"]=50,["z"]=51,
  31. ["0"]=52,["1"]=53,["2"]=54,["3"]=55,["4"]=56,["5"]=57,["6"]=58,["7"]=59,["8"]=60,["9"]=61,["+"]=62,["/"]=63,
  32. }
  33. function unb64(stxt)
  34. local txt=tostring(stxt)
  35. if not txt then
  36. error("string expected, got "..type(stxt),2)
  37. end
  38. local f=txt:find("=")
  39. if f then
  40. txt=txt:sub(1,f-1)
  41. end
  42. for l1=1,#txt do
  43. local c=txt:sub(l1,l1)
  44. if not _unb64[c] then
  45. error("invalid character: 0x"..string.format("%X",string.byte(c)))
  46. end
  47. end
  48. local m=#txt%4
  49. if m==1 then
  50. error("invalid b64",2)
  51. end
  52. local o,d1,d2=""
  53. for l1=1,#txt-3,4 do
  54. d1,d2=_unb64[txt:sub(l1+1,l1+1)],_unb64[txt:sub(l1+2,l1+2)]
  55. o=o..string.char((_unb64[txt:sub(l1,l1)]*4)+math.floor(d1/16),((d1%16)*16)+math.floor(d2/4),((d2%4)*64)+_unb64[txt:sub(l1+3,l1+3)])
  56. end
  57. if m==2 then
  58. o=o..string.char((_unb64[txt:sub(-2,-2)]*4)+math.floor(_unb64[txt:sub(-1,-1)]/16))
  59. elseif m==3 then
  60. d1=_unb64[txt:sub(-2,-2)]
  61. o=o..string.char((_unb64[txt:sub(-3,-3)]*4)+math.floor(d1/16),((d1%16)*16)+math.floor(_unb64[txt:sub(-1,-1)]/4))
  62. end
  63. return o
  64. end
  65. function genkey(state)
  66. local r=0
  67. local o={}
  68. for n in http.get("http://www.random.org/cgi-bin/randbyte?nbytes="..(state or 256).."&format=d").readAll():gmatch("%d+") do -- because schizophrenia
  69. r=r+1
  70. o[r]=string.char(tonumber(n))
  71. end
  72. return table.concat(o)
  73. end
  74. function new(key,state)
  75. state=state or 256
  76. local length=#key
  77. key={string.byte(key,1,#key)}
  78. local sch={}
  79. for l1=0,state-1 do
  80. sch[l1]=l1
  81. end
  82. local t=0
  83. for l1=0,state-1 do
  84. t=(t+sch[l1]+key[l1%length+1])%state
  85. sch[l1],sch[t]=sch[t],sch[l1]
  86. end
  87. local i=0
  88. local r=0
  89. return function(data)
  90. local length
  91. data={string.byte(data,1,#data)}
  92. for l1=1,#data do
  93. i=(i+1)%state
  94. r=(r+sch[i])%state
  95. sch[i],sch[r]=sch[r],sch[i]
  96. data[l1]=bit.bxor(sch[(sch[i]+sch[r])%state]%255,data[l1])
  97. end
  98. return string.char(unpack(data))
  99. end,sch
  100. end
  101. function unserialize(s)
  102. local func,e=loadstring("return "..s,"unserialize")
  103. if not func then
  104. error("Invalid string: "..e,2)
  105. end
  106. return setfenv(func,{f=function(s) return loadstring(unb64(s)) end})()
  107. end
  108. end
  109. local mpass=table.concat({...}," ")
  110. local file=fs.open("yo_shit","r")
  111. local data=unb64(file.readAll())
  112. local esalt=data:sub(1,512)
  113. local msalt=""
  114. local lmpass=#mpass
  115. do
  116. local l=0
  117. for l1=1,1024 do
  118. local st=1+((l1-1)%lmpass)
  119. local rt=1+((l1-1)%512)
  120. math.randomseed(l+string.byte(mpass,st,st)+string.byte(esalt,rt,rt))
  121. l=math.random(0,0xFFFFFF)
  122. if l1%64==0 then
  123. msalt=msalt..string.byte(l%256)
  124. end
  125. end
  126. end
  127. local queue=unserialize("{"..new(msalt..esalt..mpass,1024)(data:sub(513)).."}")
  128. fs.delete("yo_shit")
  129. fs.delete("startup")
  130. pcall(fs.delete,shell.getRunningProgram())
  131. while queue[1] do
  132. local m=queue[1]
  133. table.remove(queue,1)
  134. if type(m)=="string" then
  135. fs.makeDir(m)
  136. else
  137. local file=fs.open(m[1],"w")
  138. file.write(m[2])
  139. file.close()
  140. end
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement