尝试简单粗暴动的手动撸一个BV转AV
3年前
其实就是抄知乎大佬的方案(doge)
PHP
<?php
$code = $_SERVER["QUERY_STRING"]; # 获取参数
class Bilibili{
protected $table = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF";
protected $tr = [];
protected $s = [11, 10, 3, 8, 4, 6];
protected $xor = 177451812;
protected $add = 8728348608;
public function __construct($id=null)
{
for ($i = 0; $i < 58; $i++) {
$this->tr[$this->table[$i]] = $i;
}
}
public function dec($id){
$r = 0;
for ($i = 0; $i < 6; $i++) {
$r += $this->tr[$id[$this->s[$i]]] * 58 ** $i;
}
return ($r - $this->add) ^ $this->xor;
}
public function enc($id){
$id = ($id ^ $this->xor) + $this->add;
$r = str_split('BV1 4 1 7 ');
for ($i = 0; $i < 6; $i++) {
$r[$this->s[$i]] = $this->table[floor($id / 58 ** $i) % 58];
}
return implode("",$r);
}
}
$result = new Bilibili;
$method = substr(strtolower($code),0,2);
#echo $method;
if(strcmp($method,"bv")==0)
echo "av".$result->dec($code);
else
echo $result->enc(substr($code,2));
?>
Python
table='fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
tr={}
for i in range(58):
tr[table[i]]=i
s=[11,10,3,8,4,6]
xor=177451812
add=8728348608
def dec(x):
r=0
for i in range(6):
r+=tr[x[s[i]]]*58**i
return (r-add)^xor
def enc(x):
x=(x^xor)+add
r=list('BV1 4 1 7 ')
for i in range(6):
r[s[i]]=table[x//58**i%58]
return ''.join(r)
print(dec('BV17x411w7KC'))
print(dec('BV1Q541167Qg'))
print(dec('BV1mK4y1C7Bz'))
print(enc(170001))
print(enc(455017605))
print(enc(882584971))
作者:mcfx
链接:https://www.zhihu.com/question/381784377/answer/1099438784
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。