Last active
September 4, 2023 14:08
-
-
Save ayuusweetfish/d3c676db403e260e1530432d7d44015b to your computer and use it in GitHub Desktop.
Reconstruction of the `date2drp2` algorithm found in the "VOCALOID5 Libraries Installer", bundled with VOCALOID5 ESV for macOS by SilverFox (https://4download.net/209-yamaha-vocaloid-full-version.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
const char *shifttable = "23456789ABCDEFGHKLMNPRSTWXYZ"; | |
const char *convtable[] = { | |
"BELKCFHDGA27SZT8M9W43N6XR5YP", | |
"ABCDEFGHKLMNPRSTWXYZ23456789", | |
"E8AF2B93D46K7H5CGYPNWZRTLXMS", | |
"BK5C6HD2A7F43E89LZGYMNXRWPST", | |
"23456789ABCDEFGHKLMNPRSTWXYZ", | |
"T7S4WZBYRPXNMF8L9AD2EKCH5G63", | |
"9H5KGYXL4MBWA3DC2NZFPERT6S78", | |
"XWKTLHRSBMA2DCY3ZNPG865F47E9", | |
"AD2EKCH5G6", | |
"G6DP9R4SHN", | |
"M2DHE7A8KW", | |
"FS2NGC6PK9", | |
"M7EBX3CYGZ", | |
"AT5W8BDH4P", | |
}; | |
const int tab1[][13] = { | |
{8,1,7,5,2,1,7,5,2,1,7,5,2}, | |
{1,8,2,9,3,8,2,9,3,8,2,9,3}, | |
{8,6,6,1,8,6,6,1,8,6,6,1,8}, | |
{6,9,2,7,3,9,2,7,3,9,2,7,3}, | |
{9,1,8,2,6,1,8,2,6,1,8,2,6}, | |
{1,1,3,2,7,1,3,2,7,1,3,2,7}, | |
{1,7,3,4,9,7,3,4,9,7,3,4,9}, | |
{7,8,2,1,4,8,2,1,4,8,2,1,4}, | |
{8,6,8,7,8,6,8,7,8,6,8,7,8}, | |
{6,3,8,7,5,3,8,7,5,3,8,7,5}, | |
{3,2,4,3,2,2,4,3,2,2,4,3,2}, | |
{2,7,5,9,1,7,5,9,1,7,5,9,1}, | |
{7,8,4,6,9,8,4,6,9,8,4,6,9}, | |
{8,3,6,4,2,3,6,4,2,3,6,4,2}, | |
{3,9,7,0,7,9,7,0,7,9,7,0,7}, | |
{9,2,4,1,8,2,4,1,8,2,4,1,8}, | |
}; | |
const int tab2[][13] = { | |
{0,1,8,8,7,1,8,8,7,1,8,8,7}, | |
{1,2,3,0,4,2,3,0,4,2,3,0,4}, | |
{2,1,5,0,8,1,5,0,8,1,5,0,8}, | |
{1,0,1,0,1,0,1,0,1,0,1,0,1}, | |
{0,1,1,0,2,1,1,0,2,1,1,0,2}, | |
{1,2,9,0,4,2,9,0,4,2,9,0,4}, | |
{2,5,0,3,0,5,0,3,0,5,0,3,0}, | |
{5,0,5,0,5,0,5,0,5,0,5,0,5}, | |
{0,7,0,2,1,7,0,2,1,7,0,2,1}, | |
{7,9,0,1,5,9,0,1,5,9,0,1,5}, | |
{9,0,1,1,0,0,1,1,0,0,1,1,0}, | |
{0,1,1,0,3,1,1,0,3,1,1,0,3}, | |
{1,2,3,1,1,2,3,1,1,2,3,1,1}, | |
{2,1,2,2,3,1,2,2,3,1,2,2,3}, | |
{1,9,1,2,8,9,1,2,8,9,1,2,8}, | |
{9,8,0,1,9,8,0,1,9,8,0,1,9}, | |
}; | |
static inline int hex2i(char c) | |
{ | |
if (c == 'K') return 0; | |
if (c == 'L') return 1; | |
return (c <= '9' ? c - '0' : c - 'A' + 10); | |
} | |
static inline int hex2pos(char c) | |
{ | |
for (int i = 0; i < 28; i++) if (shifttable[i] == c) return i; | |
return -1; | |
} | |
static inline char i2hex(int x) | |
{ | |
return (x <= 9 ? x + '0' : x - 10 + 'A'); | |
} | |
int8_t DecodeID(const char *s, char *t) | |
{ | |
if (strlen(s) != 16) return 0; | |
memcpy(t, s, 14); | |
const int *t1 = tab1[hex2i(s[15])]; | |
const int *t2 = tab2[hex2i(s[14])]; | |
for (int i = 1; i < 14; i++) t[i] = shifttable[(hex2pos(t[i]) - t1[i] + 28) % 28]; | |
for (int i = 1; i < 14; i++) t[i] = shifttable[(hex2pos(t[i]) - t2[i] + 28) % 28]; | |
for (int i = 0; i < 14; i++) { | |
char *p = strchr(convtable[i], t[i]); | |
if (p != NULL) t[i] = i2hex(p - convtable[i]); | |
} | |
return 1; | |
} | |
int main() | |
{ | |
char t[16] = { 0 }; | |
DecodeID("BXENFF42PWRK4XE7", t); puts(t); // 005114I0040000 | |
DecodeID("BXENFF42PWRK4XE8", t); puts(t); // 02E3P7MH9B498C | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment