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'm not really familiar with the multibase project, or it's goals -- but I found this repo while looking for a general Base36 encoding/decoding class.
I thought i should point out that the Base36.java helper class can not handle encoding an empty byte[] such that the resulting string can be decoded back into an empty byte[]of the same size
Important
In any (in = new byte[x]) -> encode -> decode -> out situation, the resulting byte[] out will always have two extra bytes -- and re-encoding the out array as a string will always have 2 extra characters.
The problem does not exist as long as there is a single set bit anywhere in the byte[] input
consider the following trivial example...
for (int i = 0; i < 10; i++) {
byte[] in = new byte[i];
String s = Base36.encode(in);
byte[] out = Base36.decode(s);
System.out.println(i + ":0=" + in.length + " -> " + s);
System.out.println(i + ":0=" + out.length + " <- " + Base36.encode(out));
if (0 < in.length) {
in[in.length-1] = 1;
s = Base36.encode(in);
out = Base36.decode(s);
System.out.println(i + ":1=" + in.length + " -> " + s);
System.out.println(i + ":1=" + out.length + " <- " + Base36.encode(out));
}
System.out.println();
}
I'm not really familiar with the multibase project, or it's goals -- but I found this repo while looking for a general Base36 encoding/decoding class.
I thought i should point out that the
Base36.javahelper class can not handle encoding an emptybyte[]such that the resulting string can be decoded back into an emptybyte[]of the same sizeImportant
In any
(in = new byte[x]) -> encode -> decode -> outsituation, the resultingbyte[] outwill always have two extra bytes -- and re-encoding theoutarray as a string will always have 2 extra characters.The problem does not exist as long as there is a single set bit anywhere in the
byte[]inputconsider the following trivial example...
...the output is...