Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- crypt={}
- function crypt.xor(a,b)
- b=b:rep(math.ceil(#a/#b)):sub(1,#a)
- local o=""
- for l1=1,#a do
- o=o..string.char(bit.bxor(a:sub(l1,l1):byte(),b:sub(l1,l1):byte()))
- end
- return o
- end
- function crypt.rot13(txt)
- return txt:gsub("%l",function(c)
- return string.char(((c:byte()-84)%26)+97)
- end):gsub("%u",function(c)
- return string.char(((c:byte()-52)%26)+65)
- end)
- end
- function crypt.rot47(txt)
- txt=txt:gsub(".",function(c) if c:byte()<127 and c:byte()>32 then return string.char((((c:byte()-33)+47)%94)+33) end end)
- return txt
- end
- function crypt.tohex(txt)
- return ({txt:gsub(".",function(c) return string.format("%02x",c:byte()) end)})[1]
- end
- function crypt.fromhex(txt)
- return ({txt:gsub("%X",""):gsub("%x%x?",function(c) return string.char(tonumber("0x"..c)) end)})[1]
- end
- hook.new("command_rot13",function(user,chan,txt)
- return crypt.rot13(txt)
- end,{
- desc="most secure encryption ever made",
- group="fun",
- })
- hook.new("command_rot47",function(user,chan,txt)
- return crypt.rot47(txt)
- end,{
- desc="second most secure encryption ever made",
- group="fun",
- })
- function crypt.space(txt)
- return tobase(txt,nil,"01234567")
- :gsub("0","\226\128\139")
- :gsub("1","\226\128\138")
- :gsub("2","\226\128\137")
- :gsub("3","\226\128\136")
- :gsub("4","\194\160")
- :gsub("5","\226\128\128")
- :gsub("6","\226\128\175")
- :gsub("7","\226\129\159")
- end
- function crypt.unspace(txt)
- return tobase(txt
- :gsub("\226\128\139","0")
- :gsub("\226\128\138","1")
- :gsub("\226\128\137","2")
- :gsub("\226\128\136","3")
- :gsub("\194\160","4")
- :gsub("\226\128\128","5")
- :gsub("\226\128\175","6")
- :gsub("\226\129\159","7")
- ,"01234567")
- end
- function crypt.color(txt,cl)
- cl=tobase(cl,nil,"0123456789ABCDEF")
- return txt:gsub("%S",function(char)
- if cl~="" then
- local o="\3"..tobase(cl:sub(1,1),"0123456789ABCDEF","0123456789",2)..char
- cl=cl:sub(2)
- return o..(#cl==0 and "\15" or "")
- end
- end)
- end
- function crypt.decolor(txt)
- local o=""
- for cl in txt:gmatch("\3(%d%d)") do
- o=o..string.format("%X",tonumber(cl))
- end
- return tobase(o,"0123456789ABCDEF")
- end
- crypt.hash={}
- for k,v in pairs(crypto.list("digests")) do
- hook.new({"command_"..v},function(user,chan,txt)
- return crypto.digest(v,txt)
- end)
- crypt.hash[v]=function(txt)
- return crypto.digest(v,txt)
- end
- end
- crypt.encrypt={}
- for k,v in pairs(crypto.list("ciphers")) do
- crypt.encrypt[v]=function(pass)
- return crypto.encrypt.new(v,pass)
- end
- end
- crypt.decrypt={}
- for k,v in pairs(crypto.list("ciphers")) do
- crypt.decrypt[v]=function(pass)
- return crypto.decrypt.new(v,pass)
- end
- end
- hook.new({"command_hash","command_digest"},function(user,chan,txt)
- local err,res=pcall(crypto.digest,txt:match("^(%S+) ?(.*)$"))
- return res
- end)
- function crypt.salt(len)
- return crypto.rand.bytes(len)
- end
- local bxor=bit.bxor
- local ror=bit.ror
- local rshift=bit.rshift
- local band=bit.band
- local bnot=bit.bnot
- function chars2num(txt)
- return (txt:byte(1)*16777216)+(txt:byte(2)*65536)+(txt:byte(3)*256)+(txt:byte(4))
- end
- function limit(num)
- return band(num)
- end
- local function num2chars(num,l)
- local out=""
- for l1=1,l or 4 do
- out=string.char(math.floor(num/(256^(l1-1)))%256)..out
- end
- return out
- end
- local k={
- [0]=0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
- }
- function sha256(txt)
- local h0=0
- local h1=0
- local h2=0
- local h3=0
- local h4=0
- local h5=0
- local h6=0
- local h7=0
- local len=#txt
- txt=txt.."\128"..("\0"):rep(64-((len+9)%64))..num2chars(8*len,8)
- local w={}
- for chunkind=1,len,64 do
- local rawchunk=txt:sub(chunkind,chunkind+63)
- local chunk={}
- for i=1,64,4 do
- chunk[math.floor(i/4)]=chars2num(rawchunk:sub(i))
- end
- for i=0,15 do
- w[i]=chunk[i]
- end
- for i=16,63 do
- local s0=bxor(ror(w[i-15],7),ror(w[i-15],18),rshift(w[i-15],3))
- local s1=bxor(ror(w[i-2],17),ror(w[i-2],19),rshift(w[i-2],10))
- w[i]=w[i-16]+s0+w[i-7]+s1
- end
- local a=h0
- local b=h1
- local c=h2
- local d=h3
- local e=h4
- local f=h5
- local g=h6
- local h=h7
- for i=0,63 do
- local S1=bxor(ror(e,6),ror(e,11),ror(e,25))
- local ch=bxor(band(e,f),band(bnot(e),g))
- local temp1=limit(limit(h+S1)+limit(ch+k[i]+w[i]))
- local S0=bxor(ror(a,2),ror(a,13),ror(a,22))
- local maj=bxor(band(a,b),band(a,c),band(b,c))
- local temp2=S0+maj
- a,b,c,d,e,f,g,h=limit(temp1+temp2),a,b,c,limit(d+temp1),e,f,g
- end
- h0,h1,h2,h3,h4,h5,h6,h7=limit(h0+a),limit(h1+b),limit(h2+c),limit(h3+d),limit(h4+e),limit(h5+f),limit(h6+g),limit(h7+h)
- end
- return num2chars(h0)..num2chars(h1)..num2chars(h2)..num2chars(h3)..num2chars(h4)..num2chars(h5)..num2chars(h6)..num2chars(h7)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement