b站bv转av

b站将av视频号换成了更高级的bv号,转化代码如下:(python)
bv to av:

av to bv:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#bv to av:
bv=input()
c=[]
for i in bv:
c=c+[i]
c=c[2:]
table={'1':13,'2':12,'3':46,'4':31,'5':43,'6':18,'7':40,'8':28,'9':5,'A':54,'B':20,'C':15,'D':8,'E':39,'F':57,'G':45,'H':36,'J':38,'K':51,
'L':42,'M':49,'N':52,'P':53,'Q':7,'R':4,'S':9,'T':50,'U':10,'V':44,'W':34,'X':6,'Y':25,'Z':1,'a':26,'b':29,'c':56,'d':3,'e':24,'f':0,
'g':47,'h':27,'i':22,'j':41,'k':16,'m':11,'n':37,'o':2,'p':35,'q':21,'r':17,'s':33,'t':30,'u':48,'v':23,'w':55,'x':32,'y':14,'z':19}
d=[]
for i in range(len(bv)-2):
d=d+[table[c[i]]]
f=d[0]*58**6+d[1]*58**2+d[2]*58**4+d[3]*58**8+d[4]*58**5+d[5]*58**9+d[6]*58**3+d[7]*58**7+d[8]*58+d[9]
f=bin(f-100618342136696320)
f=list(f[2:])
g=0
h=[]
for i in '1010100100111011001100100100':
if f[g]==str(i):
h=h+['0']
else:
h=h+['1']
g=g+1
av=''.join(h)
av='av'+str(int(h,2))
print(av)
1
2
#示例:input:bv17x411w7KC
# output:av170001

代码原版:

作者(author):mcfx
链接(link):https://www.zhihu.com/question/381784377/answer/1099438784
来源(from):知乎

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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))
#out:
#170001
#455017605
#882584971
#BV17x411w7KC
#BV1Q541167Qg
#BV1mK4y1C7Bz