Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tob64,unb64,genkey,new,unserialize
- do
- local _tob64={
- [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",
- "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",
- "0","1","2","3","4","5","6","7","8","9","+","/"
- }
- function tob64(stxt)
- local txt=tostring(stxt)
- if not txt then
- error("string expected, got "..type(stxt),2)
- end
- local d,o,d1,d2,d3={string.byte(txt,1,#txt)},""
- for l1=1,#txt-2,3 do
- d1,d2,d3=d[l1],d[l1+1],d[l1+2]
- 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]
- end
- local m=#txt%3
- if m==1 then
- o=o.._tob64[math.floor(d[#txt]/4)].._tob64[((d[#txt]%4)*16)].."=="
- elseif m==2 then
- 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].."="
- end
- return o
- end
- local _unb64={
- ["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,
- ["O"]=14,["P"]=15,["Q"]=16,["R"]=17,["S"]=18,["T"]=19,["U"]=20,["V"]=21,["W"]=22,["X"]=23,["Y"]=24,["Z"]=25,
- ["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,
- ["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,
- ["0"]=52,["1"]=53,["2"]=54,["3"]=55,["4"]=56,["5"]=57,["6"]=58,["7"]=59,["8"]=60,["9"]=61,["+"]=62,["/"]=63,
- }
- function unb64(stxt)
- local txt=tostring(stxt)
- if not txt then
- error("string expected, got "..type(stxt),2)
- end
- local f=txt:find("=")
- if f then
- txt=txt:sub(1,f-1)
- end
- for l1=1,#txt do
- local c=txt:sub(l1,l1)
- if not _unb64[c] then
- error("invalid character: 0x"..string.format("%X",string.byte(c)))
- end
- end
- local m=#txt%4
- if m==1 then
- error("invalid b64",2)
- end
- local o,d1,d2=""
- for l1=1,#txt-3,4 do
- d1,d2=_unb64[txt:sub(l1+1,l1+1)],_unb64[txt:sub(l1+2,l1+2)]
- 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)])
- end
- if m==2 then
- o=o..string.char((_unb64[txt:sub(-2,-2)]*4)+math.floor(_unb64[txt:sub(-1,-1)]/16))
- elseif m==3 then
- d1=_unb64[txt:sub(-2,-2)]
- 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))
- end
- return o
- end
- function genkey(state)
- local r=0
- local o={}
- for n in http.get("http://www.random.org/cgi-bin/randbyte?nbytes="..(state or 256).."&format=d").readAll():gmatch("%d+") do -- because schizophrenia
- r=r+1
- o[r]=string.char(tonumber(n))
- end
- return table.concat(o)
- end
- function new(key,state)
- state=state or 256
- local length=#key
- key={string.byte(key,1,#key)}
- local sch={}
- for l1=0,state-1 do
- sch[l1]=l1
- end
- local t=0
- for l1=0,state-1 do
- t=(t+sch[l1]+key[l1%length+1])%state
- sch[l1],sch[t]=sch[t],sch[l1]
- end
- local i=0
- local r=0
- return function(data)
- local length
- data={string.byte(data,1,#data)}
- for l1=1,#data do
- i=(i+1)%state
- r=(r+sch[i])%state
- sch[i],sch[r]=sch[r],sch[i]
- data[l1]=bit.bxor(sch[(sch[i]+sch[r])%state]%255,data[l1])
- end
- return string.char(unpack(data))
- end,sch
- end
- function unserialize(s)
- local func,e=loadstring("return "..s,"unserialize")
- if not func then
- error("Invalid string: "..e,2)
- end
- return setfenv(func,{f=function(s) return loadstring(unb64(s)) end})()
- end
- end
- local mpass=table.concat({...}," ")
- local file=fs.open("yo_shit","r")
- local data=unb64(file.readAll())
- local esalt=data:sub(1,512)
- local msalt=""
- local lmpass=#mpass
- do
- local l=0
- for l1=1,1024 do
- local st=1+((l1-1)%lmpass)
- local rt=1+((l1-1)%512)
- math.randomseed(l+string.byte(mpass,st,st)+string.byte(esalt,rt,rt))
- l=math.random(0,0xFFFFFF)
- if l1%64==0 then
- msalt=msalt..string.byte(l%256)
- end
- end
- end
- local queue=unserialize("{"..new(msalt..esalt..mpass,1024)(data:sub(513)).."}")
- fs.delete("yo_shit")
- fs.delete("startup")
- pcall(fs.delete,shell.getRunningProgram())
- while queue[1] do
- local m=queue[1]
- table.remove(queue,1)
- if type(m)=="string" then
- fs.makeDir(m)
- else
- local file=fs.open(m[1],"w")
- file.write(m[2])
- file.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement