zamicol / BaseConverter

Zamicol's Base Converter - Convert arbitrary bases with arbitrary alphabets.
https://convert.zamicol.com
BSD 3-Clause "New" or "Revised" License
25 stars 4 forks source link

Leading zeroes are dropped when both the input alphabet and string start with a 0 #4

Closed Spotlightsrule closed 4 years ago

Spotlightsrule commented 4 years ago

I am using the base converter to convert hexadecimal strings into alphanumeric ones, but if the hex string starts with a zero, the leading zero gets dropped during the conversion process resulting in the output string being non-reversible due to the same output string generating both with and without the leading zero. In addition, this only seems to occur when running the code in NodeJS and not in the web browser where the zero magically appears in the reversal process despite the two different strings resulting in the same output. My parameters to re-produce the issue are as follows: Input alphabet: 0123456789abcdef Input string: 090e5c14c2237ecbc906879d50ae1b12 Output alphabet: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

The resulting output string both with and without the leading zero in the input string: H5UaOom3uXr7KMPbuIFHe

UPDATE: I just tried this with a different input alphabet and string, and I was able to trigger the bug there too. This seems to occur whenever both the input alphabet and string begin with 0, so for example the following parameters will also trigger it: Input alphabet: 01234abc Input string: 0143ac4cb213411abcbbac Output alphabet: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

zamicol commented 4 years ago

This is a duplicate of #1. Your leading zero is a padding character.

It's a problem of defining behavior.

Do we just want padding characters transferred over 1:1? Include a checkbox that says "copy padding characters"?

Just FYI, you can share links using the "Share" button:

https://convert.zamicol.com/?in=090e5c14c2237ecbc906879d50ae1b12&inAlpha=0123456789abcdef&outAlpha=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

zamicol commented 4 years ago

This should be fixed now: https://convert.zamicol.com/?in=090e5c14c2237ecbc906879d50ae1b12&inAlpha=0123456789abcdef&outAlpha=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&pad=true