Skip to content

Instantly share code, notes, and snippets.

@journey-ad
Forked from mimosa/bilibili_api.lua
Created June 15, 2017 11:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save journey-ad/6183aaa1a434eef07bd3fb28ed77a3d7 to your computer and use it in GitHub Desktop.
Save journey-ad/6183aaa1a434eef07bd3fb28ed77a3d7 to your computer and use it in GitHub Desktop.
B站 api key 规则,每3小时轮换一个 :(
function string.fh(str)
return (str:gsub('..', function (cc)
return string.char(tonumber(cc, 16))
end))
end
function sort_nums()
return ("6337393836663535306539363566613865616264646435653033363665356466"):fh()
end
bit = require('bit')
lmd5 = require('md5')
function x(a, b)
return bit.bor(a, b) - bit.band(a, b)
end
utility = {}
function utility.d_tv_box(str, key, skey)
local binary_str = ""
for i=1,#str/4 do
local index = (i - 1) * 4 + 1
if(i == 1) then
index = 1
end
local seg = string.sub(str, index, index+3)
local decrypted = x(tonumber(skey..seg, 16), key)
binary_str = binary_str..string.format("%04x",decrypted)
end
return binary_str
end
function utility.check_tv_box(model, s)
local snum = sort_nums()
return utility.d_tv_box(snum, model, s)
end
function utility.get_tv_box_m()
-- f3bb208b3d081dc8 0-3
-- 4fa4601d1caa8b48 4-7
-- 452d3958f048c02a 8-11
-- 86385cdc024c0f6c 12-15
-- 5256c25b71989747 16-19
-- e97210393ad42219 20-23
-- return {1="f3bb208b3d081dc8",
return {
'66336262323038623364303831646338',
'34666134363031643163616138623438',
'34353264333935386630343863303261',
'38363338356364633032346330663663',
'35323536633235623731393839373437',
'65393732313033393361643432323139'
}
end
ak = utility.get_tv_box_m()[2]
ak = ak:fh()
print(ak)
as = utility.check_tv_box(1481126400, '8e3')
md5str = lmd5.sumhexa(as)..'BlUa'
as = lmd5.sumhexa(md5str)
print(as)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment