You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Spotlightsrule
changed the title
Leading zeroes are dropped in hexadecimal base conversions
Leading zeroes are dropped when both the input alphabet and string start with a 0
Jul 14, 2020
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
The text was updated successfully, but these errors were encountered: