3

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.

3

2 Answers 2

3

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/

Sign up to request clarification or add additional context in comments.

Comments

1

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.

3 Comments

Would it be possible for you to provide a sample of this in python or ruby? For example, I want to base36 encode a string.
@Bradford: Well, which part of the implementation are you having trouble with?
I have this ruby script I'm trying to write, but am stuck trying to Base36 encode the encrypted value. I posted the problem on SO earlier today here. I can base36 encode a number just fine. My problem is the encrypted value is not a digest. Maybe I screwed that up some how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.