Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base X string encoding

I'm looking for a routine that will encode a string (stream of bytes) into an arbitrary base/alphabet (like base64 encoding but I get to choose the alphabet). I've seen a few routines that do base X encoding for a number, but not for a string.

like image 666
Paul Stone Avatar asked Feb 28 '26 10:02

Paul Stone


2 Answers

There is my implementation of BaseX (BaseN) encoding algorithm: https://github.com/KvanTTT/BaseNcoding.

Also you can experiment with different alphabets and parameters at demo-site: http://kvanttt.github.io/BaseNcoding/

like image 143
Ivan Kochurkin Avatar answered Mar 02 '26 15:03

Ivan Kochurkin


Every algorithm I've seen (and written) for this has a sequence of characters, and does a divmod of the number by the length of the sequence, uses the mod for the index into the sequence for the digit character, and feeds the div back into the process.

like image 21
Ignacio Vazquez-Abrams Avatar answered Mar 02 '26 13:03

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!