常量
//常量 const a2bAddEnc = 8728348608; const a2bXorEnc = 0b1010100100111011001100100100; const a2bEncIndex = [11, 10, 3, 8, 4, 6]; const a2bEncTable = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF";
bv号转av号
//bv号转av号
function bv2av(bv) {
temp = 0;
for (i = 0; i < a2bEncIndex.length; i++) {
if (a2bEncTable.indexOf(bv[a2bEncIndex[i]]) == -1) {
return "请输入正确的BV号!"
} else {
temp += a2bEncTable.indexOf(bv[a2bEncIndex[i]]) * Math.pow(a2bEncTable.length, i)
}
}
temp = temp - a2bAddEnc ^ a2bXorEnc;
return "av" + temp
}
//av号转bv号
function av2bv(av) {
av = av.splice("av")[0]
temp = "BV1@@4@1@7@@";
for (i = 0; i < a2bEncIndex.length; i++) {
temp = temp.substring(0, a2bEncIndex[i]) + a2bEncTable[Math.floor(((av ^ a2bXorEnc) + a2bAddEnc) / Math.pow(a2bEncTable.length, i)) % a2bEncTable.length] + temp.substring(a2bEncIndex[i] + 1)
}
return temp
}
合并后
console.error("BV17x411w7KC");
<span class="token keyword">const</span> a2bAddEnc <span class="token operator">=</span> <span class="token number">8728348608</span><span class="token punctuation">;</span> <span class="token keyword">const</span> a2bXorEnc <span class="token operator">=</span> <span class="token number">0b1010100100111011001100100100</span><span class="token punctuation">;</span> <span class="token keyword">const</span> a2bEncIndex <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">11</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
const a2bEncTable = “fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF”;
<span class="token keyword">function</span> <span class="token function">bv2av</span><span class="token punctuation">(</span><span class="token parameter">bv</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> temp <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator"><</span> a2bEncIndex<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>a2bEncTable<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span>bv<span class="token punctuation">[</span>a2bEncIndex<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token string">"请输入正确的BV号!"</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> temp <span class="token operator">+=</span> a2bEncTable<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span>bv<span class="token punctuation">[</span>a2bEncIndex<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">*</span> Math<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>a2bEncTable<span class="token punctuation">.</span>length<span class="token punctuation">,</span> i<span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> temp <span class="token operator">=</span> temp <span class="token operator">-</span> a2bAddEnc <span class="token operator">^</span> a2bXorEnc<span class="token punctuation">;</span> <span class="token keyword">return</span> <span class="token string">"av"</span> <span class="token operator">+</span> temp <span class="token punctuation">}</span> <span class="token keyword">function</span> <span class="token function">av2bv</span><span class="token punctuation">(</span><span class="token parameter">av</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> av <span class="token operator">=</span> av<span class="token punctuation">.</span><span class="token function">splice</span><span class="token punctuation">(</span><span class="token string">"av"</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> temp <span class="token operator">=</span> <span class="token string">"BV1@@4@1@7@@"</span><span class="token punctuation">;</span> <span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator"><</span> a2bEncIndex<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> temp <span class="token operator">=</span> temp<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> a2bEncIndex<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">+</span> a2bEncTable<span class="token punctuation">[</span>Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">(</span>av <span class="token operator">^</span> a2bXorEnc<span class="token punctuation">)</span> <span class="token operator">+</span> a2bAddEnc<span class="token punctuation">)</span> <span class="token operator">/</span> Math<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>a2bEncTable<span class="token punctuation">.</span>length<span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">%</span> a2bEncTable<span class="token punctuation">.</span>length<span class="token punctuation">]</span> <span class="token operator">+</span> temp<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span>a2bEncIndex<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> temp <span class="token punctuation">}</span>
评论区