A small MySQL UDF library for making encoding/decoding base24 strings written in Golang.
The base24 implementation used for this is the same that Microsoft used for their product keys, which uses the following characters, in this order:
2 3 4 6 7 8 9 b c d f g h j k m p q r t v w x y
The use of all lowercase letters means this is case insensitive. You can read more about it here.
Converts the string argument to base24 encoded form and returns the result as a binary string. If the argument is not a string, it is converted to a string before conversion takes place. The result is NULL
if the argument is NULL
.
`to_base24` ( `string` )
`string`
- The string to be encoded.
select`to_base24`('abc'); -- 't8p76'
select`to_base24`(42); -- 'y7r'
select`to_base24`('42'); -- 'y7r'
select`to_base24`(0x00abcd); -- '267cj'
select`to_base24`(null); -- NULL
Takes a string encoded with the base24 encoded rules used by to_base24
and returns the decoded result as a binary string. The result is NULL if the argument is NULL or not a valid base24 string.
`from_base24` ( `string` )
`string`
- The string to be decoded.
select`from_base24`('t8p76'); -- 'abc'
select`from_base24`('T8P76'); -- 'abc'
select`from_base24`('y7r'); -- '42'
select hex(`from_base24`('267cj')); -- '00ABCD'
select`from_base24`(null); -- NULL
You will need Golang, which you can get from here https://golang.org/doc/install.
Debian / Ubuntu
sudo apt update
sudo apt install libmysqlclient-dev
You can find your MySQL plugin directory by running this MySQL query
select @@plugin_dir;
then replace /usr/lib/mysql/plugin
below with your MySQL plugin directory.
cd ~ # or wherever you store your git projects
git clone https://github.com/StirlingMarketingGroup/mysql-base24.git
cd mysql-base24
go build -buildmode=c-shared -o base24.so
sudo cp base24.so /usr/lib/mysql/plugin/ # replace plugin dir here if needed
Enable the functions in MySQL by running this MySQL query
create function`to_base24`returns string soname'base24.so';
create function`from_base24`returns string soname'base24.so';