fzakaria / ascii85 Goto Github PK
View Code? Open in Web Editor NEWA Java library for working with Ascii85, also called Base85 - a form of binary-to-text encoding
License: Other
A Java library for working with Ascii85, also called Base85 - a form of binary-to-text encoding
License: Other
I doesn't support empty byte array
@Test public void testEmpty() { byte[] empty = new byte[0]; String encoded = Ascii85.encode(empty); try { byte[] actual = Ascii85.decode(encoded); assertThat(actual, is(empty)); } catch (Exception e) { e.printStackTrace(); } }
Encoded a JPEG frame represented by byte array with original length 25820 into a Ascii85 string with 32259 length. Which supposed to be actually 32275 = 25820 * 5 / 4;
Then try to decode that string using Ascii85.decode(); so the Allocated ByteBuffer is 25807 = 32259 * 4 / 5, which is less than original byte array length of 25820;
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:164)
at java.nio.ByteBuffer.put(ByteBuffer.java:642)
Ascii85.decode(Ascii85.java:143)
So somehow encoded string turns out to be shorter than byteArrLen * 5/4, which breaks assumption in decode and it causes the exception.
Thanks
When decoding, the formula for the output size is "input_size * 4 / 5", which does account for the fact that when input contains only 'z's output can be 4 times as large as the output.
What is the intended behaviour of the decode function (ASCII to binary), when the input string contains characters that are neither ASCII nor whitespace? Should it fail or maybe the invalid characters should just be ignored?
SecureRandom random = new SecureRandom();
byte[] randoms = new byte[128];
random.nextBytes(randoms);
String encoded = Ascii85.encode(randoms);
try {
System.out.println(toHexString(MessageDigest.getInstance("MD5").digest(randoms)));
System.out.println(toHexString(MessageDigest.getInstance("MD5").digest(Ascii85.decode(encoded))));
} catch (Exception e) {
e.printStackTrace();
}
This short program outputs two different hashes. Does this library not work for random bytes?
Hi Farid,
I ported your excellent ascii85 to kotlin here
I see you are way into several language... it's time for Kotlin! ๐
If you want I can push it and also implement gradle ๐
Hi,
First of all, thanks for the lib. It seems that the lib is not on maven central as advertised. Is that something that is planned to be fixed?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.