mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-24 12:07:39 +08:00
添加 av/bv conv
This commit is contained in:
parent
5bb19095c8
commit
3ec69df9b8
@ -6,5 +6,5 @@ package cc.sukazyo.cono.morny;
|
|||||||
public class GradleProjectConfigures {
|
public class GradleProjectConfigures {
|
||||||
public static final String VERSION = "0.8.0.8";
|
public static final String VERSION = "0.8.0.8";
|
||||||
public static final String CODENAME = "putian";
|
public static final String CODENAME = "putian";
|
||||||
public static final long COMPILE_TIMESTAMP = 1665999835121L;
|
public static final long COMPILE_TIMESTAMP = 1666028272898L;
|
||||||
}
|
}
|
||||||
|
38
src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java
Normal file
38
src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnegative;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class BiliTool {
|
||||||
|
|
||||||
|
private static final long V_CONV_XOR = 177451812L;
|
||||||
|
private static final long V_CONV_ADD = 8728348608L;
|
||||||
|
private static final char[] BV_TABLE = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF".toCharArray();
|
||||||
|
private static final int TABLE_INT = BV_TABLE.length;
|
||||||
|
private static final Map<Character, Integer> BV_TABLE_REVERSED = new HashMap<>();
|
||||||
|
static { for (int i = 0; i < BV_TABLE.length; i++) BV_TABLE_REVERSED.put(BV_TABLE[i], i); }
|
||||||
|
private static final char[] BV_TEMPLATE = "1 4 1 7 ".toCharArray();
|
||||||
|
private static final int[] BV_TEMPLATE_FILTER = new int[]{9, 8, 1, 6, 2, 4};
|
||||||
|
|
||||||
|
@Nonnegative
|
||||||
|
public static long toAv (@Nonnull String bv) {
|
||||||
|
long av = 0;
|
||||||
|
for (int i = 0; i < BV_TEMPLATE_FILTER.length; i++) {
|
||||||
|
av += BV_TABLE_REVERSED.get(bv.charAt(BV_TEMPLATE_FILTER[i])) * Math.pow(TABLE_INT,i);
|
||||||
|
}
|
||||||
|
return (av-V_CONV_ADD)^V_CONV_XOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static String toBv (@Nonnegative long av) {
|
||||||
|
av = (av^V_CONV_XOR)+V_CONV_ADD;
|
||||||
|
final char[] bv = BV_TEMPLATE.clone();
|
||||||
|
for (int i = 0; i < BV_TEMPLATE_FILTER.length; i++) {
|
||||||
|
bv[BV_TEMPLATE_FILTER[i]] = BV_TABLE[(int)(Math.floor(av/(Math.pow(TABLE_INT, i)))%TABLE_INT)];
|
||||||
|
}
|
||||||
|
return String.copyValueOf(bv);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
src/test/java/cc/sukazyo/cono/morny/util/TestBiliTool.java
Normal file
30
src/test/java/cc/sukazyo/cono/morny/util/TestBiliTool.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
|
|
||||||
|
import static cc.sukazyo.cono.morny.util.BiliTool.*;
|
||||||
|
|
||||||
|
public class TestBiliTool {
|
||||||
|
|
||||||
|
private static final String AV_BV_DATA_CSV = """
|
||||||
|
17x411w7KC, 170001
|
||||||
|
1Q541167Qg, 455017605
|
||||||
|
1mK4y1C7Bz, 882584971
|
||||||
|
1T24y197V2, 688730800
|
||||||
|
""";
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource(textBlock = AV_BV_DATA_CSV)
|
||||||
|
void testAvToBv (String bv, int av) {
|
||||||
|
Assertions.assertEquals(bv, toBv(av));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@CsvSource(textBlock = AV_BV_DATA_CSV)
|
||||||
|
void testBvToAv (String bv, int av) {
|
||||||
|
Assertions.assertEquals(av, toAv(bv));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user