fix: avbv转换
This commit is contained in:
@ -1,51 +1,52 @@
|
|||||||
// ignore_for_file: constant_identifier_names
|
// ignore_for_file: constant_identifier_names, non_constant_identifier_names
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class IdUtils {
|
class IdUtils {
|
||||||
static const String TABLE =
|
static final XOR_CODE = BigInt.parse('23442827791579');
|
||||||
'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF';
|
static final MASK_CODE = BigInt.parse('2251799813685247');
|
||||||
static const List<int> S = [11, 10, 3, 8, 4, 6]; // 位置编码表
|
static final MAX_AID = BigInt.one << (BigInt.from(51)).toInt();
|
||||||
static const int XOR = 177451812; // 固定异或值
|
static final BASE = BigInt.from(58);
|
||||||
static const int ADD = 8728348608; // 固定加法值
|
|
||||||
static const List<String> r = [
|
static const data =
|
||||||
'B',
|
'FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf';
|
||||||
'V',
|
|
||||||
'1',
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'4',
|
|
||||||
'',
|
|
||||||
'1',
|
|
||||||
'',
|
|
||||||
'7',
|
|
||||||
'',
|
|
||||||
''
|
|
||||||
];
|
|
||||||
|
|
||||||
/// av转bv
|
/// av转bv
|
||||||
static String av2bv(int av) {
|
static String av2bv(int aid) {
|
||||||
int x_ = (av ^ XOR) + ADD;
|
List<String> bytes = List.filled(12, '0', growable: false);
|
||||||
List<String> newR = [];
|
int bvIndex = bytes.length - 1;
|
||||||
newR.addAll(r);
|
BigInt tmp = (MAX_AID | BigInt.from(aid)) ^ XOR_CODE;
|
||||||
for (int i = 0; i < S.length; i++) {
|
while (tmp > BigInt.zero) {
|
||||||
newR[S[i]] =
|
bytes[bvIndex] = data[(tmp % BASE).toInt()];
|
||||||
TABLE.characters.elementAt((x_ / pow(58, i).toInt() % 58).toInt());
|
tmp = tmp ~/ BASE;
|
||||||
|
bvIndex -= 1;
|
||||||
}
|
}
|
||||||
return newR.join();
|
final tmpValue = bytes[3];
|
||||||
|
bytes[3] = bytes[9];
|
||||||
|
bytes[9] = tmpValue;
|
||||||
|
|
||||||
|
final tmpValue2 = bytes[4];
|
||||||
|
bytes[4] = bytes[7];
|
||||||
|
bytes[7] = tmpValue2;
|
||||||
|
|
||||||
|
return bytes.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// bv转bv
|
/// bv转av
|
||||||
static int bv2av(String bv) {
|
static int bv2av(String bvid) {
|
||||||
int r = 0;
|
List<String> bvidArr = bvid.split('');
|
||||||
for (int i = 0; i < S.length; i++) {
|
final tmpValue = bvidArr[3];
|
||||||
r += (TABLE.indexOf(bv.characters.elementAt(S[i])).toInt()) *
|
bvidArr[3] = bvidArr[9];
|
||||||
pow(58, i).toInt();
|
bvidArr[9] = tmpValue;
|
||||||
}
|
|
||||||
return (r - ADD) ^ XOR;
|
final tmpValue2 = bvidArr[4];
|
||||||
|
bvidArr[4] = bvidArr[7];
|
||||||
|
bvidArr[7] = tmpValue2;
|
||||||
|
|
||||||
|
bvidArr.removeRange(0, 3);
|
||||||
|
BigInt tmp = bvidArr.fold(BigInt.zero,
|
||||||
|
(pre, bvidChar) => pre * BASE + BigInt.from(data.indexOf(bvidChar)));
|
||||||
|
return ((tmp & MASK_CODE) ^ XOR_CODE).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 匹配
|
// 匹配
|
||||||
|
|||||||
Reference in New Issue
Block a user