diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 2c188e6..d7c6301 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -6,5 +6,5 @@ package cc.sukazyo.cono.morny; public class GradleProjectConfigures { public static final String VERSION = "0.8.0.8"; public static final String CODENAME = "putian"; - public static final long COMPILE_TIMESTAMP = 1665999835121L; + public static final long COMPILE_TIMESTAMP = 1666028272898L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java b/src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java new file mode 100644 index 0000000..b222828 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/util/BiliTool.java @@ -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 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); + } + +} diff --git a/src/test/java/cc/sukazyo/cono/morny/util/TestBiliTool.java b/src/test/java/cc/sukazyo/cono/morny/util/TestBiliTool.java new file mode 100644 index 0000000..125d9c6 --- /dev/null +++ b/src/test/java/cc/sukazyo/cono/morny/util/TestBiliTool.java @@ -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)); + } + +}